Bug 6238 - ifstream::getline(...) has problems reading file after long line.
Summary: ifstream::getline(...) has problems reading file after long line.
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libstdc++ (show other bugs)
Version: unknown
: P3 normal
Target Milestone: ---
Assignee: Benjamin Kosnik
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2002-04-09 08:16 UTC by Tom Brunner
Modified: 2003-07-25 17:33 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
ifstreamtest.C (509 bytes, application/octet-stream)
2003-05-21 15:17 UTC, Tom Brunner
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Tom Brunner 2002-04-09 08:16:01 UTC
When attempting to read a long line with
ifstream::getline(), the fist part of the line, up to the 
limit specified in the call, is correct.  Subsequent calls
to getline return nothing.  The attached source code exposes
this bug on all gcc versions that I have tried it on on
my Linux box.  On other compilers (on Irix, OSF1, HP-UX,
and AIX), this program runs as expected.
(Returns chunks of the line until the file is finished.)

Release:
all stdlib++'s that I've tested

Environment:
Redhat 7.2, gcc 2.96 20000731 (Red Hat Linux 7.1 2.96-98), gcc 3.0.2 20010905 (Red Hat Linux 7.1 3.0.1-3), gcc version 3.1 20020325 (prerelease)

How-To-Repeat:
Compile the attached code with g++ (one of the versions
listed above).  Run the executable.  The input file name
can be changed to any file with long lines.
Comment 1 Benjamin Kosnik 2002-04-09 11:50:40 UTC
Responsible-Changed-From-To: unassigned->bkoz
Responsible-Changed-Why: Mine.
Comment 2 Benjamin Kosnik 2002-04-09 11:50:40 UTC
State-Changed-From-To: open->analyzed
State-Changed-Why: Thanks for the clear description, well-designed test case. I've reproduced this on linux. More shortly.....
    
    -benjamin
Comment 3 Benjamin Kosnik 2002-04-09 12:16:21 UTC
State-Changed-From-To: analyzed->closed
State-Changed-Why: This isn't a bug. The specification for getline says that failbit will be set if n items are read without hitting the delimiter. That's what is happening here.
    
    If you change
    
      while(!infile.eof() && record_count < 200)
    
    to
    
      while(infile.good())
    
    You'll get the results you expect. 
    
    -benjamin