I have three map<string,int> instances. All three contain student names and and their marks. The first map contains computer students, second one contains medical students and the third one contains commerce students. I know I have to use <iomanip>library and setw. What I don't get is how do I iterate through all three at the same time to print them together? Can anyone help? I want it to be printed on the console as:
COMPUTER MEDICAL COMMERCE
joey 45 ed 20 harold 50
malisa 36 jane 60 aron 70
emily 60 judy 70 barney 45
So far what I have but this just prints one map after the other
map<string,int> ::const_iterator it;
cout<<endl;
cout<<setw(36)<<"COMPUTER STUDENTS"<<endl;
for( it = one.begin(); it != one.end(); ++it)
{
cout <<setw(20)<<it->first;
cout <<setw(5)<<it->second<<endl;
}
cout<<setw(36)<<"MEDICAL STUDENTS"<<endl;
for( it = two.begin(); it != two.end(); ++it)
{
cout <<setw(20)<<it->first;
cout <<setw(5)<<it->second<<endl;
}
cout<<setw(36)<<"COMMERCE STUDENTS"<<endl;
for(it = three.begin(); it != three.end(); ++it)
{
cout <<setw(20)<<it->first;
cout <<setw(5)<< it->second<<endl;
}`
Aucun commentaire:
Enregistrer un commentaire