-4

I have an "array" of strings defined as such:

typedef map<int, string> strArr;

Whenever I do this:

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

The compiler tells me that there's no match for 'operator!' Why is this so, and how can I fix this?

EDIT: Is there a way of making this work with bool operator! ()!

Lee Yi
  • 517
  • 6
  • 17

1 Answers1

5

With !args[1], you're trying to call operator! on a std::string, and indeed, the error message is right: std::string has no operator!.

To check whether an element exists in a std::map, use find. It will return std::map::end if the specified key is not in the map:

if (args.find(1) == args.end()) { ... }
Emil Laine
  • 41,598
  • 9
  • 101
  • 157