[C++]Nested map problem.

Aaah I see what you mean. I think that's exactly what the exercise meant. Will give it a shot tomorrow.

PS : Would I need to use 2 for loops to iterate through the map then?
 
Aaah I see what you mean. I think that's exactly what the exercise meant. Will give it a shot tomorrow.

PS : Would I need to use 2 for loops to iterate through the map then?

Yeah you would iter through the keys to get the values, then iter again over those pairs.
 
Instead of using iters you can use .find on the map which will return you the other map.
 
Instead of using iters you can use .find on the map which will return you the other map.

You still have to iterate through the inner map.

So the iteration would be something like

my_map<string, int>::iterator inner;
my_map::iterator find_value = my_map.find(a);

for ( inner = find_value -> second.begin(); inner != find_value -> second.end(); inner++ )
{
cout << find_value -> first << inner -> first << inner -> second;
}
That's more or less how I did it this morning. But thanks, your idea solved it for me :D.
 
You still have to iterate through the inner map.

So the iteration would be something like

my_map<string, int>::iterator inner;
my_map::iterator find_value = my_map.find(a);

for ( inner = find_value -> second.begin(); inner != find_value -> second.end(); inner++ )
{
cout << find_value -> first << inner -> first << inner -> second;
}
That's more or less how I did it this morning. But thanks, your idea solved it for me :D.

Cool yeah you would iter in the other map like you said.
 
Top
Sign up to the MyBroadband newsletter
X