STL map inside map C++

Posted by Prasanth Madhavan on Stack Overflow See other posts from Stack Overflow or by Prasanth Madhavan
Published on 2010-12-23T06:50:05Z Indexed on 2010/12/23 6:54 UTC
Read the original article Hit count: 335

Filed under:
|
|

In c++ STL map, i have a definition like

   map<string, map<int, string> >;

and i iterate it using the following code.

   for( map<string, map<int, string> >::iterator ii=info.begin(); ii!=info.end(); ++ii){
       for(map<int, string>::iterator j=ii->second.begin(); j!=ii->second.end();++j){
           cout << (*ii).first << " : " << (*j).first << " : "<< (*j).second << endl;
       }
   }

My doubt is is this the correct way to iterate or is there a better way to do so? The above code works for me. But m looking for a more elegant solution.

© Stack Overflow or respective owner

Related posts about c++

Related posts about stl