wxFileOutputStream

If you are using wxDev-C++ for your wxWidgets design, please ask your questions here instead of in IDE Related.
Post Reply
newbee
In need of some credit
In need of some credit
Posts: 8
Joined: Sat Nov 19, 2011 8:54 pm

wxFileOutputStream

Post by newbee »

Hi,

Code: Select all

int i;
float f;
wxString str;
wxFile file(wxT("scores.dat"));
wxFileOutputStream out(file);
wxDataOutputStream outdata(out);
out.SeekO(0,wxFromEnd);
outdata<<5<<0.012;
outdata<<wxT("I cant write this text twice");

wxFileInputStream in(wxT("scores.dat"));
wxDataInputStream data(in);
//in.SeekI(0,wxFromStart);
data>>i>>f;
data>>str;
But everytime I run the code I see the same content.How to write at the end of the file?
User avatar
doublemax
Moderator
Moderator
Posts: 19158
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxFileOutputStream

Post by doublemax »

Pass " wxFile::write_append" as mode when opening the file:

Code: Select all

wxFile file(wxT("scores.dat"), wxFile::write_append);
http://docs.wxwidgets.org/stable/wx_wxfile.html#wxfile

Also, for stuff like this, take a look at wxTextFile which may be easier to use:
http://docs.wxwidgets.org/stable/wx_wxt ... wxtextfile
Use the source, Luke!
newbee
In need of some credit
In need of some credit
Posts: 8
Joined: Sat Nov 19, 2011 8:54 pm

Re: wxFileOutputStream

Post by newbee »

Thanks for the reply.I feel comfortable when using wxTextFile, but can we use it for binary data?
Also,Im confused with that we have wxFileInputStream and wxDataInputStream.I create objects for both of them.Seek function of which should I use?
Post Reply