问题:
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?或者有没有其他方法可以对地图进行排序?