Page 1 of 1

Writing to config file

Posted: Mon Mar 06, 2006 9:28 am
by Raghu
This is the piece of code I had written to write to the config file

wxFileInputStream NamesStream("config.txt");
wxFileConfig *ConfigNames = new wxFileConfig(NamesStream);
bool b = ConfigNames->Write("ramu","[email protected]");

The return value is true but it doesn't write anything to the file.

I don't have any problem reading from the config file. Can somebody tell me whats the problem with Writing to config file.

Posted: Mon Mar 06, 2006 9:51 am
by phlox81
Don't you need an Outputstream if you wann write to a file ???

Posted: Mon Mar 06, 2006 10:14 am
by Raghu
Thanks for finding that mistake.Does the same file config.txt can be assigned to output stream.

Posted: Mon Mar 06, 2006 11:00 am
by Raghu
I tried replacing input stream with output stream, but it doesn't seem to work. Can u just provide a code snippet for reading and writing into same config file.

Posted: Mon Mar 06, 2006 11:24 am
by phlox81
I usually work with std:: o/ifstream for writing/reading files.
So I am not familiar with the wxFile stuff.
Acutally, if I look at the Docs, wxFileConfig::Save could be worth a try. ... configsave


Posted: Mon Mar 06, 2006 11:44 am
by Raghu
That was the problem. I was not Saving after writing. Thanks a lot.

Posted: Mon Mar 06, 2006 12:56 pm
by barbarello
Here is the code I use (after been helped on this forum)

Code: Select all

wxFileConfig * file_config = new wxFileConfig(wxEmptyString, wxEmptyString,"My PATH");
file_config->SetPath("/My GROUP NAME");
file_config->Write("My KEY NAME", "String to add");
If this can help you....