Sign in to follow this  

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

This topic is 4166 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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

This topic is 4166 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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