Original assumption about a map in C ++

I initialize the map map<string,int> ex; in c ++. I could not find contains_key or a similar function in stl, so I just use ex[inputString]++;

The debugger shows that int is initialized to zero correctly, is this a good guess?

+7
c ++ stl map
source share
1 answer

Yes, values ​​that do not exist when accessed using operator[] are built by default. For numeric values, this is 0.

However, you are looking for the count method:

 bool hasElement = ex.count("element"); 
+7
source share

All Articles