如何爲地圖創建自己的比較器? - 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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章