problem with ifstream

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I use mingw 3.1.0 (gcc 3.2.3) and 3.4 (from wxDevCpp - gcc 3.4.2).
I have a problem with ifstream reading a text file and using the newer gcc.
I read a file line by line but sometimes the line doesn't start from
the beginning.

http://control.dsi.unifi.it/~cialdi/test.zip

here is an example. Just type make to build two executables, one built
using gcc 3.2.3 (test_ok.exe) and the other using gcc 3.4.2
(test_nook.exe).

here is the piece of code:
   ifstream fi;
   fi.open(filename);
   fi.clear();
   fi.seekg (0);
   char str[512];
   do
   {
       cout << endl << fi.tellg();
       fi >> str;
       cout << ": "<< str << " - " << fi.tellg() << endl;
   }while(fi.good());

It read a line from a file and print it out, with the addition of the
file positions before and after the line was read.

I use kernel.mot to test the read.

if this file is:
S02B0000433A5C4C61766F72695C6265725C626F6F746C6F61645C6B65726E656C5C6B65726E656C5C516B6C0B
S214FFB40001006DF60FF61B977A0300FFFDB4683A4E
S214FFB410CA0868BA7A0200FFFEDB6E2A00CDEA8011

test_ok output is:
0: S02B0000433A5C4C61766F72695C6265725C626F6F746C6F61645C6B65726E656C5C6B65726E656C5C516B6C0B
- 95
95: S214FFB40001006DF60FF61B977A0300FFFDB4683A4E - 140
140: S214FFB410CA0868BA7A0200FFFEDB6E2A00CDEA8011 - 185

and test_nook output is:
0: S02B0000433A5C4C61766F72695C6265725C626F6F746C6F61645C6B65726E656C5C6B65726E656C5C516B6C0B
- 95
95: 4FFB40001006DF60FF61B977A0300FFFDB4683A4E - 140
140: 14FFB410CA0868BA7A0200FFFEDB6E2A00CDEA8011 - 185


I wonder if it is a bug of gcc. Maybe I'm wrong using (or not using)
some compilation parameter.

thanks

--
Massimiliano Cialdi
cialdi@xxxxxxxxx
m.cialdi@xxxxxxxx


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux