Sign in to follow this  
v0dKA

std::map - checking if a certain key has a value yet

Recommended Posts

std::map provides a certain feature which is sometimes useful, but in my case, harmful. When accessing the elements of a map using a key, if the key-value pair does not exist for the specified key, it is automatically created and inserted into the map. This is not desired in my case. I am actually trying to check whether or not a certain key has been initialized yet. How can I do this?

Share this post


Link to post
Share on other sites
This is only the case if you use operator[] to access elements of the map. You can use map::find() to determine if a given key is present in the map.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this