std::multimap 按照key遍歷
阿新 • • 發佈:2017-10-31
clas get es2017 技術分享 nor 分享 har getchar str
#include <iostream> #include <unordered_map> using namespace std; int main() { unordered_multimap<int, int> umap; umap.insert({ 1, 1 }); umap.insert({ 2, 2 }); umap.insert({ 2, 1 }); umap.insert({ 3, 3 }); umap.insert({ 3, 1 }); umap.insert({ 3, 2 });for(auto it = umap.begin(); it != umap.end(); it = umap.upper_bound(it->first)) { auto range = umap.equal_range(it->first); cout << it->first << ":" << endl; while(range.first != range.second) { cout << " " << range.first->second << endl;++range.first; } } getchar(); return 0; }
運行結果:
std::multimap 按照key遍歷