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

前端 未结 7 1506
轻奢々
轻奢々 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:53

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

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

提交回复
热议问题