Jump to content
  • Advertisement
Sign in to follow this  

Quick stl map question.

This topic is 4348 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

I'm storing settings and values in a map. At the end of the program I would like to be able to save out the current settings as they may have been changed. I figured it would be easy enough to create an iterator and print out the key and value, but I can't figure out how to get access to the value of the key.

Share this post


Link to post
Share on other sites
Advertisement
Elements in std::map are made of of both the key AND the value, using a std::pair to wrap them up. You can access it like this:


typedef std::map<std::string, std::string> settings_map;

void outputSettings(const settings_map& settings)
{
// Start settings file
//...

// Output each setting
for(settings_map::const_iterator it=settings.begin() ; it!=settings.end() ; ++it)
{
const settings_map::key_type& key = it->first;
const settings_map::value_type& value = it->second;
// Output key & value
}

// Finish settings file
//...
}


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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!