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

前端 未结 7 1502
轻奢々
轻奢々 2020-12-28 13:41

I have a map declared as follows:

map < string , list < string > > mapex ; list< string > li;

How can I disp

7条回答
  •  灰色年华
    2020-12-28 13:48

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

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

提交回复
热议问题