查找find
判断key值是否存在(1),通过find查看
map<int ,string> m;
m[132] = "456";m[456]="789";m[789]="123";
map<int,string>::iterator iter = m.find(132);
if(iter != m.end()){
cout << iter->first << "->" << iter->second << endl;
}
结果:
判断key值是否存在(2),通过count函数查看
map<int ,string> m;
m[132] = "456";m[456]="789";m[789]="123";
if(m.count(123)){
cout << "123的key已经存在";
}else{
m[123] = "147";
}
for(map<int,string>::iterator it = m.begin(); it != m.end(); it++){
cout<<it->first<<"->"<<it->second<<endl;
}