Printing a multilevel container I have these struct(s) to keep data about temperature measurement: 

// data structure representing day 
struct Day{
   vector&lt;double&gt;hour;
   Day();
}; 
Day::Day(): hour(24){
   for(int i=0; i&lt; hour.size();++i) hour[i]=not_a_reading;
}

// data structure representing month
struct Month{
    int month;
    vector&lt;Day&gt;day;
    Month(): month(not_a_month),day(32) { }
};

// data structure representing year
struct Year{
    int year;
    vector&lt;Month&gt;month;
    Year(): month(12) { }
};

// vector holding measured data
vector&lt;Year&gt;yrs;


I am trying to write a program to print all the data inside yrs. Here is what I got so far:

void print_year(ostream os, vector&lt;Year&gt;&amp; v){
for(size_t i=0; i&lt;v.size(); ++i){
    os &lt;&lt; "{year " &lt;&lt; v[i].year; 
    for (size_t j=0; j&lt;v[i].month.size(); ++j){
        os &lt;&lt; " {month " &lt;&lt; v[i].month[j].month;
        for (size_t k=0; k&lt;v[i].month[j].day.size();++k){
            os &lt;&lt; '(' &lt;&lt;v[i].month[j].day &lt;&lt;" "&lt;&lt; v[i].month[j].day[k].hour;
            //--^^---- (No &lt;&lt; operator matches these operands) WHY?
            os  &lt;&lt; ') ';
            }
        os &lt;&lt; "}";
        }
    os &lt;&lt; "}";
    }
}


If I have one measurement on: 10th of Jan 1992 at 10 o'clock with temperature 61.6 Fahrenheit and two on: 11th and 22th of Feb 1992 with temperatures: 64 and 65.2. The output (format) will be: (year 1992 { month jan ( 10 61.5)} {month feb (11 64) (22 65.2)})

I'm probably using the vector access operator[] wrong.

I was trying to fix it and got to this: 

void print_year(ostream os, vector&lt;Year&gt;&amp; v){
for(size_t i=0; i&lt;v.size(); ++i){
    os &lt;&lt; "{year " &lt;&lt; v[i].year; 
    for (size_t j=0; j&lt;v[i].month.size(); ++j){
        os &lt;&lt; " {month " &lt;&lt; month_input_tb[v[i].month[j].month];
        for (size_t k=0; k&lt; v[i].month[j].day.size();++k){
            os &lt;&lt;  '('&lt;&lt; k &lt;&lt;" "; // loop counter coincides with day of the month
            for (size_t z=0; z &lt; v[i].month[j].day[k].hour.size(); ++z){
                os &lt;&lt; v[i].month[j].day[k].hour[z];
                os  &lt;&lt; ')';
        }
        os &lt;&lt; "}";
    }
    os &lt;&lt; "}";
}


}

Then I saw your (Loki Astari) answer and I am writing separate &lt;&lt; operators now.
I would try and simplify that each structure knows how to print itself:

int main()
{
    Year    year;
    // Load data into year.

    std::cout &lt;&lt; year;

    // You can print a vector of years with:
    std::vector&lt;Year&gt;   yrs;

    std::copy(std::begin(yrs), std::end(yrs),
              std::ostream_iterator&lt;Year&gt;(std::cout, "\n"));

    // or a Simple loop:
    for(auto const&amp; year: yrs) {
        std::cout &lt;&lt; year &lt;&lt; "\n";
    }

};


To make this work you need to define an operator&lt;&lt; for Year

struct Year{
    int year;
    vector&lt;Month&gt;month;
    Year(): month(12) { }

    friend std::ostream&amp; operator&lt;&lt;(std::ostream&amp; str, Year const&amp; year)
    {
        str &lt;&lt; "{year " &lt;&lt; year.year;
        for(auto const&amp; month : year.month) {
            str &lt;&lt; month;
        }
        str &lt;&lt; "}"; 
        return str;
    }
};


So the print for Year is defined in terms of printing for a Month object. So you know have to define how to print a Month. Which in turn will print some Day objects. So you will also have to define how to print a Day object.

The problem you are seeing:

os &lt;&lt; '(' &lt;&lt; v[i].month[j].day &lt;&lt;" "&lt;&lt; v[i].month[j].day[k].hour;
//           ^^^^^^^^^^^^^^^^^
//    This is a vector.
//    The stream class does not know how to stream a vector.
//    Did you mean `v[i].month[j].month`