How can I determine if a key in std::map doesn't exist?
"How can I determine if a key in std::map doesn't exist?"
IE
std::map<string,string>
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
map <string, string> myMap;
string str1 = "Key";
if (myMap.count(str1) == 0) {
cout<<"Key does not exist"<<endl;
}
else {
cout<<"Key Exist"<<endl;
}
|
|
myMap.find( "Key" ) == myMap.end(); // true == does not exist
|
Topic archived. No new replies allowed.