如何通过键对unordered_map进行排序?我需要打印按键排序的unordered_map.
解决方法
std::unordered_map<int,int> unordered; std::map<int,int> ordered(unordered.begin(),unordered.end()); for(auto it = ordered.begin(); it != ordered.end(); ++it) std::cout << it->second;
std::unordered_map<int,int> unordered; std::map<int,int> ordered(unordered.begin(),unordered.end()); for(auto it = ordered.begin(); it != ordered.end(); ++it) std::cout << it->second;