Question about multimap
May 5, 2008 at 6:10pm UTC
Hi everyone :)
I want to display the contents of a complex multimap.
Here is part of the code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
class CPlane {
public :
string brand;
unsigned hours;
};
bool operator <(const CPlane &ob1, const CPlane &ob2) {
return ob1.brand < ob2.brand;
}
class CAirtravel {
public :
string company, nation;
map <CPlane, unsigned > plane;
multimap <string, unsigned > destination;
};
bool operator <(const CAirtravel &ob1, const CAirtravel &ob2) {
return ob1.company < ob2.company;
}
class CAirport {
string name;
unsigned flight;
multimap <CAirtravel, unsigned > airtravel;
public :
void info() {
multimap <CAirtravel, unsigned >::iterator iair = airtravel.begin();
for (; iair != airtravel.end(); iair++) {
cout<<"Airport: " <<name;
cout<<"\nFlight number: " <<flight;
cout<<"\n\nData of companies:" ;
cout<<"\n\nCompany: " <<iair->first.company;
cout<<"\nNationality: " <<iair->first.nation;
map <CPlane, unsigned > pl(iair->first.plane);
map <CPlane, unsigned >::iterator ipl = pl.begin();
cout<<"\n\nList of company's planes:" ;
for (;ipl != pl.end(); ipl++) {
cout<<"\nBrand: " <<ipl->first.brand;
cout<<"\nFlight hours: " <<ipl->first.hours;
cout<<"\nDestinations: " <<ipl->second;
}
multimap <string, unsigned > ds(iair->first.destination);
multimap <string, unsigned >::iterator ids = ds.begin();
cout<<"\n\nList of company's destinations:" ;
for (;ids != ds.end(); ids++) {
cout<<"\n\nName of destination: " <<ids->first;
cout<<"\nFlights to " <<ids->first<<": " <<ids->second;
}
cout<<"\n\nNumber of all company's flights: " <<iair->second<<endl<<endl;
}
}
If you look at function info(), you will notice that it works correctly only if one pair of elements is present in the airtravel multimap.
I think the problem is here:
1 2
map <CPlane, unsigned > pl(iair->first.plane);
multimap <string, unsigned > ds(iair->first.destination);
This maps don't change their content after the first cycle.
How can I remove them before the new cycle ?
I want to recreate them at every new cycle and to give them the values of the next airtravel key ?
Last edited on May 5, 2008 at 6:11pm UTC
Topic archived. No new replies allowed.