Advertisement Jump to content
Sign in to follow this  
Thergothon

Quick stl map question.

This topic is 4594 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
it->first and it->second were what i was looking for. thanks guys.

[Edited by - Thergothon on June 26, 2006 9:07:05 AM]

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!