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

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

    I'd try the following

    void dump_list(const std::list& l) {
      for ( std::list::const_iterator it = l.begin(); l != l.end(); l++ ) {
        cout << *l << endl;
      }
    }
    
    void dump_map(const std::map>& map) {
      for ( std::map>::const_iterator it = map.begin(); it != map.end(); it++) {
        cout << "Key: " << it->first << endl;
        cout << "Values" << endl;
        dump_list(it->second);
    }
    

提交回复
热议问题