wxTextFile Confusion 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
Emerald2240
Knows some wx things
Knows some wx things
Posts: 30
Joined: Tue Dec 11, 2018 1:38 pm

wxTextFile Confusion

Post by Emerald2240 »

Hi! I'm a newbie in wxwidgets, I use codeblocks as my IDE, I recently embarked on a project to create a sort of jotter like app for instantly saving texts and loading them with emphasis on speed... But that's another story.
I originally started the project using basic C++ File save via fstream/ofstream but after that backfired I sought to use the famous wxtextfile, but every tutorial I find never seems to hit the point of a simple save example, so please can I get a good example of a Textfile save from a textctrl with a wxstring?
Thanks in advance!
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxTextFile Confusion

Post by doublemax »

using basic C++ File save via fstream/ofstream but after that backfired
What exactly was wrong with that?
I sought to use the famous wxtextfile, but every tutorial I find never seems to hit the point of a simple save example
wxTextFile is good for accessing a textfile on a line-by-line basis, from your description it doesn't sound like it's the right tool for the job.

Just use wxFile:

Code: Select all

wxString s = "a string from somewhere";
wxFile f( "d:\\test.txt", wxFile::write );
f.Write( s );  // saves using UTF8 encoding
f.Close();
https://docs.wxwidgets.org/trunk/classwx_file.html
Use the source, Luke!
Emerald2240
Knows some wx things
Knows some wx things
Posts: 30
Joined: Tue Dec 11, 2018 1:38 pm

Re: wxTextFile Confusion

Post by Emerald2240 »

Thanks Very Much for your Reply and Advice, I really appreciate it!
About your question. It Backfired in the sense I couldn't save a file with a user input file name... I tried so hard, even porting in string variables to replace the file name which obviously wasn't applicable and also the fstream class is too rigid to be ported with wxwidgets almost everything I tried resulted in error.
Thanks again! I'll try it out now
User avatar
shawnhcorey
Knows some wx things
Knows some wx things
Posts: 41
Joined: Mon Nov 19, 2012 3:29 pm
Location: The Great White North

Re: wxTextFile Confusion

Post by shawnhcorey »

Some things you might check for:

Does the user have write permissions on the directory?

Is the file being written to the root directory?

Does the name contain characters, like spaces, that the OS does not allow?

Some OSes require an extension on every file. Does the name have an extension?
WARNING: Highly caffeinated ☕. Approach with caution 🚧.
Emerald2240
Knows some wx things
Knows some wx things
Posts: 30
Joined: Tue Dec 11, 2018 1:38 pm

Re: wxTextFile Confusion

Post by Emerald2240 »

Thanks I'll check on them..
Post Reply