Last active
August 29, 2015 14:20
-
-
Save bertrandmartel/ccb6a4653a24e7f0fc5b to your computer and use it in GitHub Desktop.
[ CPP ] Find a key in a map without inserting value
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//##################### 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