如何为地图创建自己的比较器? - How can I create my own comparator for a map?

问题:

typedef map<string, string> myMap;

When inserting a new pair to myMap , it will use the key string to compare by its own string comparator.myMap插入新对时,它将使用键string通过其自己的字符串比较器进行比较。 Is it possible to override that comparator?是否可以覆盖该比较器? For example, I'd like to compare the key string by its length, not by the alphabet.例如,我想通过长度而不是字母来比较键string Or is there any other way to sort the map?或者有没有其他方法可以对地图进行排序?


解决方案:

参考: https://stackoom.com/en/question/O3Tq
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章