How can I display the content of a map on the console?

c++, dictionary, stdmap, stl

Solution

Well it depends on how you want to display them, but you can always iterate them easily:

typedef map<string, list<string>>::const_iterator MapIterator;
for (MapIterator iter = mapex.begin(); iter != mapex.end(); iter++)
{
    cout << "Key: " << iter->first << endl << "Values:" << endl;
    typedef list<string>::const_iterator ListIterator;
    for (ListIterator list_iter = iter->second.begin(); list_iter != iter->second.end(); list_iter++)
        cout << " " << *list_iter << endl;
}

Problem

I have a `map` declared as follows: ``` map < string , list < string > > mapex ; list< string > li; ``` How can I display the items stored in the above map on the console?

Original source