問題:
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?或者有沒有其他方法可以對地圖進行排序?