Alright, I've been trying this for about two hours now and making no headway.
If I have a text file, how do I load it line-by-line into wxStrings? That sounds like a stupid question, but what I've found is that:
a) the standard C++ file input won't load directly into a wxString
b) there's no way (that I can find) to convert directly from string to wxString - wxString only takes char*
c) converting from string to char* to wxString just seems stupidly convoluted
d) no where in the documentation can I find how to actually read from a file using just wxWidgets. I've examined the wxFileInputStream class, but nowhere do I see how to actually read data once it's been declared.
e) I've looked at the wxFile class, which appears to more closely resemble standard stream reading classes, but I still don't see any of the more standard reading methods, like readline.
Is there no way to read a file line-by-line in the more standard way?
File parsing and loading in C++ with wxWidgets Topic is solved
-
- wxWorld Domination!
- Posts: 1059
- Joined: Sun Dec 30, 2007 6:40 pm
- Location: Canada
Hi,
There are a number of ways to do this.
Check this useful page on the wiki which explains how to convert from char* to wxString.
http://wiki.wxwidgets.org/Converting_ev ... o_wxString
Post a reply if you're still fighting with it.
Hope that helps,
Jim
PS Welcome to the forum.
There are a number of ways to do this.
Check this useful page on the wiki which explains how to convert from char* to wxString.
http://wiki.wxwidgets.org/Converting_ev ... o_wxString
Post a reply if you're still fighting with it.
Hope that helps,
Jim
PS Welcome to the forum.
OS: Vista SP1, wxWidgets 2.8.7.
What you want to look into is wxTextFile. It works with text files on a line by line basis. Super simple to use:
Code: Select all
wxString file;
wxFileDialog fdlog(this);
if(fdlog.ShowModal() != wxID_OK) return;
file.Clear();
file = fdlog.GetPath();
wxString str;
wxTextFile tfile;
tfile.Open(file);
str = tfile.GetFirstLine();
while(!tfile.Eof())
{
str = tfile.GetNextLine();
}