Map

 1 #include<cstdio>
 2 #include<iostream>
 3 #include<map>
 4 using namespace std;
 5 
 6 int main()
 7 {
 8    map<int,string>m;
 9    m.insert(pair<int,string>(1,"1234"));
10    map<int,string>::iterator ptr;
11    m[2]="123";
12    m.insert(map<int,string>::value_type(3,"12"));          //三种插入方式
13    for(ptr=m.begin();ptr!=m.end();ptr++)
14    {
15        cout<<(*ptr).first<<" ";
16        cout<<ptr->second<<endl;
17    }
18    cout<<m.count(2)<<endl;
19    ptr=m.find(2);
20    cout<<(*ptr).first<<" ";
21    cout<<ptr->second<<endl;
22    m.erase(m.begin());
23    //同样,map与set函数类似,不一一描述了。
24    return 0;
25 }

 

posted on 2013-07-12 16:48  张狂不年轻°  阅读(137)  评论(0编辑  收藏  举报