SourceForge has been redesigned. Learn more.
Close

#745 ifstream.eof() reports false EOF

closed-fixed
gcc (462)
2005-04-25
2005-03-27
No

System:
WinXP Professional, Version 2002, SP1
MinGW-3.1.0-1
MSYS-1.0.10
gcc-core-3.4.2-20040916-1
gcc-g++-3.4.2-20040916-1

IF a text file larger than 512 bytes containing DOS
line breaks opened for reading in text mode (no
ios::binary set) AND ifstream.read() set to read mode
than 511 bytes THEN the ifstream.eof() returns TRUE
after the first read! Although, the real number of
bytes read is smaller than the requested (I think
because of translation of line ends) but the file is
not on EOF!

I found this when my program using 2048 bytes buffer to
read a text file failed to load the whole file.

#include <fstream>
using namespace std;

#define BS 512

int main (void)
{ char buf [BS+1];

ifstream f \("some.txt"\);
while \(\!f.eof \(\)\)
\{
    f.read \(buf, BS\);
    int r = f.gcount \(\);
    buf \[r\] = 0;

    fprintf \(stderr, "%d %d: %s\n", f.eof \(\), r, buf\);
\}

return 0;

}

Discussion

  • A. Haferburg

    A. Haferburg - 2005-04-04

    Logged In: YES
    user_id=1246682

    I ran into this bug, too. I'm using MinGW-3.2.0-rc-
    3.exe on Windows 2000 sp 4.

    Best regards
    Andreas

     
  • Danny Smith

    Danny Smith - 2005-04-07
    • labels: 104601 --> gcc
    • assigned_to: nobody --> dannysmith
     
  • Danny Smith

    Danny Smith - 2005-04-25
    • status: open --> closed-fixed
     
  • Danny Smith

    Danny Smith - 2005-04-25

    Logged In: YES
    user_id=11494

    Fixed in GCC 4.0.0
    Danny

     

Log in to post a comment.