#include <iostream>#include<cstdio>#include<map>//key value size makes binary search treeusing namespaceStd;map<int,string>A;intMain () {A.insert (map<int,string>::value_type (1,"Li")); A.insert (Map<int,string>::value_type (1,"LI"));//key value exists, insert failedA.insert (pair<int,string> (2,"Yang")); A.insert (Pair<int,string> (2,"YANG"));//key value exists, insert faileda[3]="Wang"; a[3]="WANG";//The key value exists and is overwrittenA.insert (Make_pair (4," Dong")); A.insert (Make_pair (4," Dong"));//key value exists, insert failedmap<int,string>:: Iterator it; for(It=a.begin (); It!=a.end (); it++) {cout<<it->first<<" "<<it->second<<Endl; } if(A.find (1)!=A.end ()) {cout<<"Find success!"<<Endl; } Else{cout<<"losing finding!"<<Endl; } if(A.count (1)==true) {cout<<"Find success!"<<Endl; } Else{cout<<"losing find!"<<Endl; } cout<<"The number of elements in the map is"<<a.size () <<Endl; A.erase (A.begin (), A.end ()); if(A.empty ()) {cout<<"map is empty"<<Endl; } Else{cout<<"map is not empty"<<Endl; } return 0;}
Common application of Map container in C++stl Library