1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| map<int,int> m; m.insert(pair<int,int>(1,10)); m.insert(pair<int,int>(2,20)); m.insert(pair<int,int>(3,30)); m.insert(pair<int,int>(4,40)); cout<<"没有插入删除前"<<endl; for(map<int,int>::iterator mt = m.begin(); mt!=m.end(); mt++){ cout<<"map的first: "<<mt->first<<" map的second: "<<mt->second<<endl; } m.insert(make_pair(5,50)); m[6] = 60; m.erase(m.begin()); cout<<"插入删除后"<<endl; for(map<int,int>::iterator mt = m.begin(); mt!=m.end(); mt++){ cout<<"map的first: "<<mt->first<<" map的second: "<<mt->second<<endl; }
cout<<"key的个数: "<<m.count(0)<<endl;
cout<<"查找key: "<<m.count(5)<<endl;
|