Looping through a list of objects
<p>I was trying to loop through a list that contains objects. I am reading in data using a weather API and storing each data member as in an object and then storing each object in a list. After I store the whole list, I want to be able to loop through the list and display the objects. I am reading in the data as Json and I am using the casablanca package to do so. All i want to do is be able to loop through my list in the displayFullForcast function in my main.cpp.
Here is my list definition:</p>

<pre><code>list&lt;Weather&gt; weather;
</code></pre>

<p>Here is my header:</p>

<pre><code>    #pragma once

    #include&lt;string&gt;
    #include&lt;iostream&gt;
    #include &lt;list&gt;
    using std::list;
    using std::string;

    //const static int MAX_DAYS = 5;

    class Weather
    {
        public:
            Weather();
            ~Weather();
            Weather(double currentTemperature, double maxTemperature,
                double minTemperature, string weatherDescription,double humidity, string time);
            list&lt;Weather&gt; weather;
        private:
            string cityState;
            double currentTemperature;
            double highTemperature;
            double lowTemperature;
            string weatherDescription;
            double humidity;
            double highestTemperature;
            double lowestTemperature;
            string time;
    };
</code></pre>

<p>Here is my implementation:</p>

<pre><code>#include "Weather.h"
#include &lt;list&gt;
#include &lt;string&gt;
#include &lt;iostream&gt;

using std::cout;
using std::endl;
using std::cin;


Weather::Weather(double currentTemperature, double maxTemperature, double minTemperature,
    string weatherDescription, double humidity, string time) :
    cityState(cityState), currentTemperature(currentTemperature), highTemperature(highTemperature), lowTemperature(lowTemperature),
    weatherDescription(weatherDescription), humidity(humidity), time(time)
{
}
Weather::Weather()
{
    cityState = "";
    currentTemperature = 0.0;
    highTemperature = 0.0;
    lowTemperature = 0.0;
    weatherDescription = "";
    humidity = 0.0;
    highestTemperature = 0.0;
    lowestTemperature = 0.0;

}

Weather::~Weather()
{

}
</code></pre>

<p>and here is my main.cpp</p>

<pre><code>void displayFullForcast()
{
    list&lt;Weather&gt;weather;
    for (list&lt;Weather&gt;::iterator it = weather.begin(); it != weather.end(); ++it)
    {
        cout &lt;&lt; *it &lt;&lt; endl;
    }

}

void displayTodayForcast()
{
    list&lt;Weather&gt;weather;
}

void displayLowHigh()
{
    list&lt;Weather&gt;weather;
}

void displayHumidity()
{
    list&lt;Weather&gt;weather;
}


void displayMenu()
{
    int choice = 0;
    cout &lt;&lt; "What option would you like to see:\n"
        &lt;&lt; "(1) Forcast for 5 days\n"
        &lt;&lt; "(2) Forcast for Today\n"
        &lt;&lt; "(3) The Lowest and Highest Temperature\n"
        &lt;&lt; "(4) Humidity for Today\n" &lt;&lt; endl;
    cin &gt;&gt; choice;
    switch (choice)
            {
            case 1: displayFullForcast();
                break;
            case 2: displayTodayForcast();
                break;
            case 3: displayLowHigh();
                break;
            case 4: displayHumidity();
                break;
            }
}



void executeWeatherQuery()
{
    http_client client(U("http://api.openweathermap.org"));
    uri_builder builder(U("/data/2.5/forecast"));
    builder.append_query(U("q"), U("Searcy,AR"));
    builder.append_query(U("appid"), U("5ee41aef99a6e283abcdd5a04d89ae67"));
    builder.append_query(U("units"), U("imperial"));
    builder.append_query(U("mode"), U("json"));

    http_response response = client.request(methods::GET, builder.to_string()).get();
    web::json::value forecastJson = response.extract_json(true).get();
    web::json::value forecastListJson = forecastJson.at(U("list"));

    if (forecastListJson.is_array())
    {
        for (size_t i = 0; i &lt; forecastListJson.size(); i++)
        {
            web::json::value forecastDayJson = forecastListJson[i];
            web::json::value mainJson = forecastDayJson.at(U("main"));
            web::json::value currentTemperatureJson = mainJson.at(U("temp"));
            double currentTemperature = 0;
            if (!currentTemperatureJson.is_null())
            {
                currentTemperature = currentTemperatureJson.as_double();
            }
            cout &lt;&lt; "Current Temperature " &lt;&lt; currentTemperature &lt;&lt; endl;

            web::json::value weatherJson = forecastDayJson.at(U("weather"))[0];
            web::json::value mainWeatherJson = weatherJson.at(U("main"));
            string weatherDescription = "";
            if (!mainWeatherJson.is_null())
            {
                weatherDescription = conversions::to_utf8string(mainWeatherJson.as_string());
            }
            cout &lt;&lt; "Weather Description " &lt;&lt; conversions::to_utf8string(weatherDescription) &lt;&lt; endl;

            web::json::value MainJson = forecastDayJson.at(U("main"));
            web::json::value minTemperatureJson = MainJson.at(U("temp"));
            double minTemperature = 0;
            if (!minTemperatureJson.is_null())
            {
                minTemperature = minTemperatureJson.as_double();
            }
            cout &lt;&lt; "Min Temp: " &lt;&lt; minTemperature &lt;&lt; endl;

            web::json::value MainMaxJson = forecastDayJson.at(U("main"));
            web::json::value maxTemperatureJson = MainMaxJson.at(U("temp"));
            double maxTemperature = 0;
            if (!maxTemperatureJson.is_null())
            {
                maxTemperature = maxTemperatureJson.as_double();
            }
            cout &lt;&lt; "Max " &lt;&lt; maxTemperature &lt;&lt; endl;

            web::json::value MainHumidityJson = forecastDayJson.at(U("main"));
            web::json::value humidityJson = MainHumidityJson.at(U("humidity"));

            double humidity = 0;
            if (!MainHumidityJson.is_null())
            {
                humidity = humidityJson.as_double();
            }
            cout &lt;&lt; "Humidity: " &lt;&lt; humidity &lt;&lt; endl;

            web::json::value MainTimeJson = forecastDayJson.at(U("dt_txt"));
            string time = "";
            if (!MainTimeJson.is_null())
            {
                time = conversions::to_utf8string(MainTimeJson.as_string());

                //time = localtime(time);
            }
            cout &lt;&lt; "Time" &lt;&lt; time &lt;&lt; endl;

            Weather WeatherForcast(currentTemperature, maxTemperature, minTemperature,
                weatherDescription, humidity, time);
            list&lt;Weather&gt;weather;
            weather.push_back(WeatherForcast);
        }
    }
}

void main()
{
    /*string location;
    cout &lt;&lt; "Please enter a city and a State (Example: Searcy,AR)" &lt;&lt; endl;
    cin &gt;&gt; location;*/
    executeWeatherQuery();


displayMenu();
}
</code></pre>

<p>** I am receiving this error still on the line cout &lt;&lt; *it &lt;&lt; endl;
Error: No operator "&lt;&lt;" matches these operands. operands types are std::ofstream and Weather. </p>