std::multimap 按照key遍历---

#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;
}

运行结果:

原文地址:https://www.cnblogs.com/tangxin-blog/p/7760591.html