stl map一对多用法

// stlMap.cpp : Defines the entry point for the console application.
//
#pragma warning (disable : 4786 ) 
#include "stdafx.h"
#include <map>;
#include <string>
#include <iostream>
#include <stdlib.h>
#include <list>;
using namespace std;

int main(int argc, char* argv[])
{

    typedef std::list<std::string> StringList;
    map<string,StringList>map_roster;
    map<string,StringList>::iterator iter;
    
    StringList slMing;

    slMing.push_back("mingfei1ÌõÏûÏ¢");
    slMing.push_back("mingfei2ÌõÏûÏ¢");
    map_roster["mingfei"]=slMing;

    slMing.erase(slMing.begin(),slMing.end());

    slMing.push_back("1ÌõÏûÏ¢");
    slMing.push_back("2ÌõÏûÏ¢");
    slMing.push_back("3ÌõÏûÏ¢");

    map_roster["ydp"]=slMing;

    iter=map_roster.find("mingfei");
//     for (;iter!=map_roster.end(); iter++)
//    {
     cout<<iter->first<<endl;
     StringList::const_iterator g = (*iter).second.begin();
     for (;g!=(*iter).second.end();g++)
     {
         cout<<(*g).c_str()<<endl;
     }

//}


    /*
    StringList::const_iterator it2=(*iter).second.begin();

        for (;it2<(*iter).second.end();it2++)
        {
            //cout<<(*it2).c_str()<<endl;
            cout<<"333"<<endl;
        }
*/

    

    system("pause");
    return 0;
}

时间: 2024-07-31 13:19:45

stl map一对多用法的相关文章

hdu 4941 stl的map&lt;node,int&gt;用法

#include<iostream> #include<cstdio> #include<cstring> #include<map> using namespace std; typedef struct node{ int x,y; bool operator<(const node &b)const { if(x==b.x) return y<b.y; else return x<b.x; } }node; int main(

STL中常用的vector,map,set 用法

STL中常用的vector,map,set 用法 C++的标准模板库(Standard Template Library,简称STL)是一个容器和算法的类库.容器往往包含同一类型的数据.STL中比较常用的容器是vector,set和map,比较常用的算法有Sort等. . 一. vector 1.声明: 一个vector类似于一个动态的一维数组. vector中可以存在重复的元素! vector<int> a;          // 声明一个元素为int类型的vector a vectot&

(转)STL中set的用法

转载自here 1.关于set map容器是键-值对的集合,好比以人名为键的地址和电话号码.相反地,set容器只是单纯的键的集合.例如,某公司可能定义了一个名为bad_checks的set容器,用于记录曾经给本公司发空头支票的客户.当想知道一个值是否存在时,使用set容器是最适合的.除了两种例外情况,set容器支持大部分的map操作,这两种例外是:set不支持下标操作,而且也没有mapped_type类型,在set容器中,value_type不是pair类型,而是与key_type相同的类型.它

(转载)STL map与Boost unordered_map的比较

原链接:传送门 今天看到 boost::unordered_map,它与 stl::map的区别就是,stl::map是按照operator<比较判断元素是否相同,以及比较元素的大小,然后选择合适的位置插入到树中.所以,如果对map进行遍历(中序遍历)的话,输出的结果是有序的.顺序就是按照operator< 定义的大小排序.而boost::unordered_map是计算元素的Hash值,根据Hash值判断元素是否相同.所以,对unordered_map进行遍历,结果是无序的. 用法的区别就是

STL map详细用法和make_pair函数

今天练习华为上机测试题,遇到了map的用法,看来博客http://blog.csdn.net/sprintfwater/article/details/8765034:感觉很详细,博主的其他内容也值得学习:后面附上今天的练习题目. 首先make_pair Pairs C++标准程序库中凡是“必须返回两个值”的函数, 也都会利用pair对象 class pair可以将两个值视为一个单元.容器类别map和multimap就是使用pairs来管理其健值/实值(key/va lue)的成对元素. pai

UVA 12096 STL map set 的使用

set这个容器也是STL库的一员,并且在algorithm内直接有 set_union set_intersection  这样求并集交集的操作 map 最方便的地方就是 支持下标访问 举例说明 : 1 #include<iostream> 2 include<cstdio> 3 #include<cstring> 4 #include<vector> 5 #include<map> 6 #include<set> 7 #includ

正确使用stl map的find,erase方法

查找某个key对应的value的方法,有2种: 方法1: typedef std::multimap<boost::uint64_t,std::string>::iterator it it = mmap_.find( nCallLetter ); if ( it != mmap_.end()) { char key[20] = {0}; sprintf(key, "%I64d",it->first); qDebug("key = %s,value = %s

map的详细用法 (转

[cpp] view plaincopy map的详细用法: map是STL的一个关联容器,它提供一对一(其中第一个可以称为关键字,每个关键字只能在map中出现一次,第二个可能称为该关键字的值)的数据处理能 力,由于这个特性,它完成有可能在我们处理一对一数据的时候,在编程上提供快速通道.这里说下map内部数据的组织,map内部自建一颗红黑树(一种非严 格意义上的平衡二叉树),这颗树具有对数据自动排序的功能,所以在map内部所有的数据都是有序的,后边我们会见识到有序的好处. 下面举例说明什么是一对

(转)STL map与Boost unordered_map

转:http://blog.csdn.net/orzlzro/article/details/7099231 今天看到 boost::unordered_map, 它与 stl::map的区别就是,stl::map是按照operator<比较判断元素是否相同,以及比较元素的大小,然后选择合适的位置插入到树中.所以,如果对map进行遍历(中序遍历)的话,输出的结果是有序的.顺序就是按照operator< 定义的大小排序. 而boost::unordered_map是计算元素的Hash值,根据Ha