Code:
#include <iostream>
#include <string>
#include <map>
using namespace std;
struct teamstats {
int points_for,
points_against,
games;
};
int main() {
int i;
map<string,struct teamstats> eg;
struct teamstats tmp;
string names[3] = { "one", "two", "three" };
/* add to map */
for (i=0;i<3;i++) {
tmp.points_for = i;
tmp.points_against = i*2;
tmp.games = 5;
eg.insert(pair<string,struct teamstats>(names[i],tmp));
}
/* iterate thru map and verify */
map<string,struct teamstats>::iterator it = eg.begin();
while(it != eg.end()) {
cout << it->first << endl;
cout << "\tfor: " << it->second.points_for
<< " against: " << it->second.points_against
<< " (" << it->second.games << " games)\n";
it++;
}
return 0;
}
Notice I left "team name" out of the struct since that is the first element of the map. The output should be:
one
for: 0 against: 0 (5 games)
three
for: 2 against: 4 (5 games)
two
for: 1 against: 2 (5 games)
Notice they are not in order.