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
Post a Comment