map:是一种键值对的容器,特色,查找很是的快,元素不能重复。
使用以前#include python
map<int ,char> mapp; cout<<mapp.size(); cout<<mapp.empty(); mapp[1001]='m';//给键值对的键对应的值赋值 mapp[1002]='w'; mapp[1003]='m'; cout<<mapp[1002];//取值。 mapp.erase(1002);//删除key为1002的值。 mapp.erase(mapp.begin());//删除的位置,必须为迭代器型。 cout<<mapp.size(); cout<<" "; mapp[1005]='w'; mapp[1006]='m'; mapp[1007]='w'; mapp[1008]='m'; map<int ,char>::iterator itor1,itor2; itor1=mapp.begin(); itor2=mapp.end(); cout<<endl; for(itor1;itor1!=itor2;itor1++) { int k=itor1->first; char v=itor1->second; cout<<k<<":"<<v<<endl; //cout<<*itor1<<" "; } cout<<endl;