Questions tagged «insertion-order»

14
跟踪插入顺序的std :: map?
我目前有一个std::map<std::string,int>将整数值存储到唯一字符串标识符的,并且确实在查询该字符串。它主要执行我想要的操作,除了它不跟踪插入顺序。因此,当我迭代地图以打印出值时,它们会根据字符串进行排序;但我希望根据(第一次)插入的顺序对它们进行排序。 我考虑过使用a vector<pair<string,int>>,但是我需要查找字符串并将整数值递增约10,000,000次,因此我不知道a是否std::vector会明显变慢。 有没有一种使用方法,std::map还是有另一个std更适合我需要的容器? [我使用的是GCC 3.4,并且我的值对可能不超过50对std::map。 谢谢。
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.