Writing to config file Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Raghu
Experienced Solver
Experienced Solver
Posts: 79
Joined: Wed Oct 19, 2005 11:33 am

Writing to config file

Post by Raghu » Mon Mar 06, 2006 9:28 am

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.

phlox81
wxWorld Domination!
wxWorld Domination!
Posts: 1387
Joined: Thu Aug 18, 2005 7:49 pm
Location: Germany
Contact:

Post by phlox81 » Mon Mar 06, 2006 9:51 am

Don't you need an Outputstream if you wann write to a file ???

Raghu
Experienced Solver
Experienced Solver
Posts: 79
Joined: Wed Oct 19, 2005 11:33 am

Post by Raghu » Mon Mar 06, 2006 10:14 am

Thanks for finding that mistake.Does the same file config.txt can be assigned to output stream.

Raghu
Experienced Solver
Experienced Solver
Posts: 79
Joined: Wed Oct 19, 2005 11:33 am

Post by Raghu » Mon Mar 06, 2006 11:00 am

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.

phlox81
wxWorld Domination!
wxWorld Domination!
Posts: 1387
Joined: Thu Aug 18, 2005 7:49 pm
Location: Germany
Contact:

Post by phlox81 » Mon Mar 06, 2006 11:24 am

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.
http://wxwidgets.org/manuals/2.6.2/wx_w ... configsave

phlox

Raghu
Experienced Solver
Experienced Solver
Posts: 79
Joined: Wed Oct 19, 2005 11:33 am

Post by Raghu » Mon Mar 06, 2006 11:44 am

That was the problem. I was not Saving after writing. Thanks a lot.

barbarello
Earned some good credits
Earned some good credits
Posts: 113
Joined: Sat Jan 07, 2006 7:22 pm
Location: Grenoble (FRANCE)

Post by barbarello » Mon Mar 06, 2006 12:56 pm

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");
file_config->Flush();
If this can help you....

Post Reply