sorting in std::map where key is a std::string

后端 未结 4 1427
-上瘾入骨i
-上瘾入骨i 2021-02-01 18:20

I have a std::map mymap

Now, if I insert values in the map like:

std::map  mymap;
mymap[\"first\"] = \"hi\";
mymap[\"third\"] = \"         


        
4条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-01 19:10

    std::map is already ordered. If you were using unordered_map, now you'd have a problem!

    Entries in std::map are ordered by the key, or itr->first. itr->second as you have it, refers to the value associated with the key.

    Further more, you're not iterating over the map, you're iterating over file_line (I don't know what that is, but I'm going to assume it's different from mymap. That is what you should be iterating over).

提交回复
热议问题