Skip to content

Instantly share code, notes, and snippets.

@bertrandmartel
Last active August 29, 2015 14:20
Show Gist options
  • Save bertrandmartel/ccb6a4653a24e7f0fc5b to your computer and use it in GitHub Desktop.
Save bertrandmartel/ccb6a4653a24e7f0fc5b to your computer and use it in GitHub Desktop.
[ CPP ] Find a key in a map without inserting value
//##################### CLASSIC MAP ###############################
std::map<std::string,std::string> map;
if (map.find(key)!=map.end()){
//key was found
}
else{
//key not found
}
//#################### POINTER MAP #################################
std::map<std::string,std::string> *map_ptr;
std::map<std::string,std::string> map_val=*map_ptr;
if (map_val.find(key)!=map.end()){
//key was found
}
else{
//key not found
}
//if (strcmp(map[key],"")!="") => will insert key if not exists
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment