C++ – How to display the content of a map on the console

c++dictionarystdmapstl

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?

Best Solution

Update (Back to the future): with C++11 range-based for loops –

std::map<Key, Value> m { ... /* initialize it */ ... };

for (const auto &p : m) {
    std::cout << "m[" << p.first << "] = " << p.second << '\n';
}