Jump to content
  • Advertisement
Sign in to follow this  
v0dKA

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

This topic is 4380 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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!