I'm trying to write simple configure file manager class.
Configure values are stored in a map<string, string> configDictionary
(first string is property, second value).
When some value in that map is changed, I want to write that new value in a configure file.
For that, I wrote a method, which is listed bellow:
key is a name of property which I want to save.
typedef map<string, string>::iterator confIterator_d; // iterator
map<string, string> configDictionary;
string configFileName; //name of the config file
string lastError; //error msg
int ConfigManager::SaveConfigFile(const string &key)
config.open(configFileName.c_str(), ios::in | ios::out);
lastError = "Can't read file.";
unsigned pos = 0;
while (getline(config, tmp))
size_t found = tmp.find(key);
if (found != string::npos)
confIterator_d it = configDictionary.find(key);
if (it != configDictionary.end())
tmp = it -> first + "=" + it -> second;
pos += tmp.length();
I'm reading file line by line. In each line
I'm looking for the key. If key is found, create new line (tmp)
and write it in the proper line of the file.
Question is, why it doesn't work? I just can't save the new value.