c++ map容器查找操作
- #include<iostream>
- #include<map>
- #include<cstring>
- using namespace std;
- int main()
- {
- map<string,int> cmap;
- cmap["op1"] = 1;
- cmap["op2"] = 2;
- string str = "samy";
- cmap.insert(make_pair(str,3));
- // for(map<string,int>::iterator ite = cmap.begin(); ite!=cmap.end();++ite)
- // {
- // cout<<ite->first<<" "<<ite->second<<endl;
- // }
- //cout<<cmap.count("Annaa")<<endl;
- map<string,int>::iterator key = cmap.find("Anna");
- if(key!=cmap.end())
- {
- cout<<key->second<<endl;
- }
- return 0;
- }