首页 > 其他 > 详细

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

时间:2017-10-31 12:01:42      阅读:332      评论:0      收藏:0      [点我收藏+]
#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遍历---

原文:http://www.cnblogs.com/tangxin-blog/p/7760591.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!