1 #include <map> 2 #include <iostream> 3 using namespace std; 4 int main() 5 { 6 map<int ,int >mapm; 7 mapm.insert(pair<int ,int>(0,200)); 8 mapm.insert(pair<int ,int>(1,300)); 9 mapm.insert(pair<int ,int>(2,400)); 10 mapm[3]=500; 11 map<int ,int >::iterator it; 12 for (it=mapm.begin();it!=mapm.end();++it) 13 { 14 cout<<it->first<<" "<<it->second<<endl; 15 } 16 cout<<"============map的大小============="<<endl; 17 int nsize=mapm.size(); 18 cout<<nsize<<endl; 19 cout<<"=========输出=============="<<endl; 20 for (int i=0;i<nsize;++i) 21 { 22 cout<<mapm[i]<<endl; 23 } 24 cout<<"==========================="<<endl; 25 map<int,int>::iterator pos=mapm.find(5); 26 27 if (pos==mapm.end()) 28 { 29 30 cout<<"====没有发现======"<<endl; 31 } 32 33 34 35 }