Print Map Elements

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
    while (true)
    {
        if (infile)
        {
            infile >> ai. airportCode >> ai. city >> ai. phoneNum;

            while (! infile. eof () )
            {
                pair <AirportMap::iterator, bool> ret;
                ret = air.insert ( pair< string, Airport> (airportCode, ai) );

                if (ret. second == false)
                {
                    ret. first -> second;
                }
            }
        }
        else break;
    }


How would I properly print out all the elements in AirportMap such as Airport Code, City, and Phone Num - along with the prices of the flights?
Last edited on
1
2
3
4
5
6
for (it = AirportMap.begin(); it != AirportMap.end(); ++it)
{
  cout << "\nAirport Code " << it -> second.airportCode
  << "\tCity " << it -> second.city
  << "\tphoneNum " << it -> second.phoneNum;
}


Note that currently, your key is a blank string:
ret = air.insert ( pair< string, Airport> (airportCode, ai) ); // airportCode is never set to anything
Last edited on
Thanks for the help Repeater. I am getting an error on the line 'for (it = AirportMap.begin(); it != AirportMap.end(); ++it'. The error is an 'unexpected type name 'AirportMap': expected expression'.

How would I fix the airportCode issue and set the key to the appropriate string?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
while (true)
    {
        if (infile)
        {
            infile >> airportCode >> city >> phoneNum;

            while (! infile. eof () )
            {
                ai. airportCode = airportCode;
                ai. city = city;
                ai. phoneNum = phoneNum;
                pair <AirportMap::iterator, bool> ret;
                ret = air.insert ( pair< string, Airport> (airportCode, ai) );

                if (ret. second == false)
                {
                    ret. first -> second;
                }
            }
        }
        else break;
    }


Would this be a possible solution?
Last edited on
1
2
3
4
5
6
for (it = air.begin(); it != air.end(); ++it)
{
  cout << "\nAirport Code " << it -> second.airportCode
  << "\tCity " << it -> second.city
  << "\tphoneNum " << it -> second.phoneNum;
}


Topic archived. No new replies allowed.