zoukankan      html  css  js  c++  java
  • multimap用法

    multimap的特点为key是可以重复的,而普通map中的key是不可以重复的。
    声明

    multimap<int, CString>mapTest;
    multimap<int, CString>::iterator pIter;
    typedef multimap<int, CString>::iterator it;
    
    插入,跟普通map相似
            mapTest.insert(PairTest(1, _T("a")));
            mapTest.insert(PairTest(1, _T("b")));
    	mapTest.insert(PairTest(1, _T("c")));
    	mapTest.insert(PairTest(2, _T("a")));
    

    遍历,主要思路为根据key,multimap的特点为key是可以重复,即一个key对应多个value。将所有key取出来,然后每个key逐个遍历。

      1取出所有的key,可以用set

            for (pIter = mapTest.begin(); pIter != mapTest.end(); pIter++)
    	{
    		setKey.insert(pIter->first);
    	}
    
    2.逐个key遍历
            pair<it, it> PairIter;
    	for (pIterKeySet = setKey.begin(); pIterKeySet != setKey.end(); pIterKeySet++)
    	{
    		int iCurrentKey = *pIterKeySet;
    		PairIter = mapTest.equal_range(iCurrentKey);
    		while (PairIter.first != PairIter.second)
    		{
    			CString csTempKey = PairIter.first->second;
    			cout<<csTempKey<<endl;
    			PairIter.first++;       //这个要的
    		}
    	}
    
    这样就可以逐个遍历了
  • 相关阅读:
    Supervisor安装与使用
    windows常用快捷键和指令
    搜索引擎使用技巧
    golang核心Goroutine和channel
    4、小程序原生底部菜单
    三、小程序值使用vant开发
    axios请求2
    3、小程序消息推送
    居中
    一、底部菜单
  • 原文地址:https://www.cnblogs.com/flysnail/p/2095475.html
Copyright © 2011-2022 走看看