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:
1 2
|
// 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.
1 2 3 4 5 6 7
|
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
1 2 3 4 5 6 7 8 9 10
|
typedef std::map< std::string, std::string > inner_t;
typedef std::map< std::string, inner_t > outer_t;
typedef outer_t::iterator outer_iter_t;
typedef inner_t::iterator inner_iter_t;
outer_t tree;
for( outer_iter_t o = tree.begin(); o != tree.end(); ++o )
for( inner_iter_t i = o->second.begin(); i != o->second.end(); ++i )
std::cout << i->first << " == " << i->second << std::endl;
|
Last edited on
Topic archived. No new replies allowed.