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

Cute picture Cute · Jun 30, 2009 · Viewed 84.4k times · Source

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?

Answer

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';
}