-
April 11th, 2011, 10:55 PM
#1
Iterating Through a Map Within a Map
I have a map of maps but I'm not sure how to iterate through the inner one.
Here's what I have so far:
The type:
Code:
// It's a map...of maps. INCEPTION
typedef map <string, map <string, string>> iniTree;
The attempted iteration; the outer one seems to be fine but I'm at a loss for what to do for the inner one.
Code:
iniTree::iterator GroupPos;
iniTree::iterator KeyPos;
for (GroupPos = myMap.begin(); GroupPos != myMap.end(); GroupPos++) {
for (KeyPos = myMap[GroupPos].begin(); KeyPos != myMap[GroupPos].end(); KeyPos++) {
}
}
If anyone can point me in the right direction, I'd really appreciate it.
-LBD
-
April 12th, 2011, 04:33 AM
#2
Re: Iterating Through a Map Within a Map
Originally Posted by LeonsBuddyDave
I have a map of maps but I'm not sure how to iterate through the inner one.
Code:
#include <string>
#include <map>
typedef std::map< std::string, std::string> MapStringToString;
typedef std::map< std::string, MapStringToString > iniTree;
iniTree myMap;
void foo()
{
iniTree::iterator GroupPos;
iniTree::iterator KeyPos;
for (GroupPos = myMap.begin(); GroupPos != myMap.end(); ++GroupPos)
{
MapStringToString& innerMap = GroupPos->second;
for (MapStringToString::iterator it = innerMap.begin(); it != innerMap.end(); ++it )
{
//...
}
}
}
Regards,
Paul McKenzie
-
April 13th, 2011, 06:20 AM
#3
Re: Iterating Through a Map Within a Map
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|