strange issue with reading files...

wx at 61131.com wx at 61131.com
Fri Jan 4 09:14:17 PST 2008


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" <rorywalsh at gmail.com>
Newsgroups: comp.soft-sys.wxwindows
To: <wx-users 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-unsubscribe at lists.wxwidgets.org
> For additional commands, e-mail: wx-users-help at lists.wxwidgets.org
>




More information about the wx-users mailing list