1 # include<map> 2 # include<cstdio> 3 # include<iostream> 4 using namespace std; 5 int main(int argc,const char *argv[]) 6 { 7 /*-----------------------------------*/ 8 //multimap对象创建,元素插入 9 //multimap<string,double> m; 10 // m.insert(pair<string,double>("Jack",300.5)); 11 // m.insert(pair<string,double>("Kity",200)); 12 //m.insert(pair<string,double>("kity",500)); 13 14 //m.insert(pair<string,double>("Jack",306)); 15 //multimap<string,double>::iterator it; 16 //for(it = m.begin();it!=m.end();it++) 17 //{ 18 // cout<<(*it).first<<":"<<(*it).second<<endl; 19 //} 20 21 /*--------------------------------------*/ 22 //元素的删除 23 //multimap<string,double> m; 24 // m.insert(pair<string,double>("Jack",300.5)); 25 // m.insert(pair<string,double>("Kity",200)); 26 //m.insert(pair<string,double>("kity",500)); 27 28 //m.insert(pair<string,double>("Jack",306)); 29 //multimap<string,double>::iterator it; 30 //for(it = m.begin(); it!=m.end(); it++) 31 //{ 32 // cout<<(*it).first<<":"<<(*it).second<<endl; 33 //} 34 //m.erase("Jack"); 35 //cout<<"the elements after deleted"<<endl; 36 //for(it=m.begin(); it!=m.end(); it++) 37 //{ 38 // cout<<(*it).first<<":"<<(*it).second<<endl; 39 //} 40 41 /*-----------------------------------*/ 42 //元素查找 43 multimap<string,double> m; 44 m.insert(pair<string,double>("Jack",300.5)); 45 m.insert(pair<string,double>("Kity",200)); 46 m.insert(pair<string,double>("kity",500)); 47 48 m.insert(pair<string,double>("Jack",306)); 49 multimap<string,double>::iterator it; 50 cout<<"all of the elements"<<endl; 51 for(it = m.begin(); it!=m.end(); it++) 52 { 53 cout<<(*it).first<<":"<<(*it).second<<endl; 54 } 55 56 cout<<"the searching result"<<endl; 57 it = m.find("Jack"); 58 if(it!=m.end()) 59 { 60 cout<<(*it).first<<":"<<(*it).second<<endl; 61 } 62 else 63 { 64 cout<<"not find it"<<endl; 65 } 66 it = m.find("Nacy"); 67 if(it!=m.end()) 68 { 69 cout<<(*it).first<<" "<<(*it).second<<endl; 70 } 71 else 72 { 73 cout<<"not find it"<<endl; 74 } 75 }