strange issue with reading files...
rory
rorywalsh at gmail.com
Fri Jan 4 09:53:16 PST 2008
On Jan 4, 7:14 pm, w... at 61131.com wrote:
> Moin Rory,
>
> did You open the file in binary mode? The default is text mode which could result in wrong positioning.
>
> Hope this helps
> Friedrich
>
> ----- Original Message -----
> From: "rory" <rorywa... at gmail.com>
>
> Newsgroups: comp.soft-sys.wxwindows
> To: <wx-us... at lists.wxwidgets.org>
> Sent: Friday, January 04, 2008 5:54 PM
> Subject: strange issue with reading files...
>
> > I've spent to whole day trying to figure out how do the following in a
> > wxwidget application:
> > 1) open a binary file, an .exe to be precise,
> > 2) read the last 10 chars from the end
> > 3) offset the file by the value contained in those last 10 chars
> > 4) retrieve everything from there till the end of the file.
>
> > I have it working without any problem in a non wxWidgets program but
> > as soon as I try to do it from my wx app it doesn't work. This is the
> > code I'm using:
>
> > std::string str, csdText;
> > char buf[10];
> > fstream inFile(appName.c_str());
> > if(!inFile) cerr << "Error";
> > inFile.seekg(-10, ios::end);
> > inFile.get(buf, sizeof(char)*10);
> > int pos = atoi(buf)+10;
>
> > wxMessageBox(buf);
> > inFile.seekg(-pos, ios::end);
>
> > csdText = "";
> > while(!inFile.eof()){
> > getline(inFile, str);
> > csdText = csdText+str;
> > }
>
> > wxMessageBox(csdText.c_str());
>
> > I've also tried with wxFile but I didn't have any joy with that
> > either. As a last resort I tried a straightforward C implementation
> > but that also fails with odd results. Can anyone see what the problem
> > might be, hopefully it is something silly I am overlooking. Please let
> > me know if you need any further info. I'm using wxWidgets 2.8. Cheers,
>
> > Rory.
>
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: wx-users-unsubscr... at lists.wxwidgets.org
> > For additional commands, e-mail: wx-users-h... at lists.wxwidgets.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: wx-users-unsubscr... at lists.wxwidgets.org
> For additional commands, e-mail: wx-users-h... at lists.wxwidgets.org
Ok, I'm now successfully opening the file using an ifstream in
ios::binary mode. Now the program does not hang but I still get
rubbish in my display boxes. When I check the same input file with
another non-gui application it displays the end of the file without
any problems so I know there are characters at the end of the binary
file. Any other ideas?
More information about the wx-users
mailing list