Hi, I wanted to open a file for input and output. How do I change from this file:
Code:
:First line
LINE_1 = foo
:Second line
LINE_2 = This is the second line.
to
Code:
:First line
LINE_1 = This is the first line.
:Second line
LINE_2 = This is the second line.
I used this file for a config file. The lines with the first character of ':' is comments. The config itself can be changed in the application.
The code I use to read the file is:
Code:
fstream filestr;
char temp[256];
char optName[256];
char optValue[256];
lstDataComp lstOptions; //typedef map<string,string> lstDataComp
filestr.open ("./data/gamedata.txt", fstream::in| fstream::out);
// Begin loading options
filestr.getline(temp,256);
while (filestr.good())
{
while ((temp[0] == ':' || temp[0] == '\r' || temp[0] == '\0' || temp[0] == '\n' || strlen(temp) == 0)&&
filestr.good())
{
filestr.getline(temp,256);
}
if (filestr.good())
{
sscanf (temp, "%s = %s",
optName, optValue);
lstOptions[string(optName)]=string(optValue);
filestr.getline(temp,256);
}
}
// End loading options
filestr.close();
The options were saved in a map container while the comments were ignored. But then I have to change the options in the application and save it again in the same config file. How do I do that without having to change the comments and other options' values???
Thanks in advance...