Quick stl map question.
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.
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 //...}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement