C++ Test if map element exists -


this question has answer here:

i have "array" of strings defined such:

typedef map<int, string> strarr; 

whenever this:

strarr args; if(!args[1]) { /*do stuff*/ } 

the compiler tells me there's no match 'operator!' why so, , how can fix this?

edit: there way of making work bool operator! ()!

with !args[1], you're trying call operator! on std::string, , indeed, error message right: std::string has no operator!.

to check whether element exists in std::map, use find. return std::map::end if specified key not in map:

if (args.find(1) == args.end()) { ... } 

Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -