This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libstdc++/14004] New: seekg/eof problem: reading from a file twice fails


When trying to read a file twice by reading the whole file through getline and 
doing a seekg(0), the eof-bit is not reset and the second reading fails.
It can be reproduced with:
#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main(int argc, char* argv[]) {
  fstream file(argv[1], std::ios::in);
  std::string line;
  while (!getline(file,line).eof())
    std::cerr << "FILE: " << line << std::endl;
  std::cerr << std::endl;
  
  file.seekg(0, std::ios::beg);
  file.seekp(0, std::ios::beg);
//file.clear();
// file.close();
//file.open("test.fasta", std::ios::in);
  std::cerr << "EOF: " << file.eof() << std::endl;
  
  while (!getline(file,line).eof())
    std::cerr << "FILE: " << line << std::endl;
  std::cerr << std::endl;
  
  return 0;
}

g++-3.3 -v:
Reading specs from /usr/lib/gcc-lib/i486-linux/3.3.3/specs
Konfiguriert mit: ../src/configure -v --enable-languages=c,c++,java,f77,pascal,
objc,ada,treelang --prefix=/usr --mandir=/usr/share/man 
--infodir=/usr/share/info --with-gxx-include-dir=/usr/include/c++/3.3 
--enable-shared --with-system-zlib --enable-nls --without-included-gettext 
--enable-__cxa_atexit --enable-clocale=gnu --enable-debug --enable-java-gc=boehm 
--enable-java-awt=xlib --enable-objc-gc i486-linux
Thread model: posix
gcc-Version 3.3.3 20040125 (prerelease) (Debian)

I tried gcc 3.2 as well and it has the same bug, but in 2.95 it works. A 
work-around is to 1. close the file 2. call file.clear() and re-open it.

-- 
           Summary: seekg/eof problem: reading from a file twice fails
           Product: gcc
           Version: 3.3.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: libstdc++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: jens dot auer-bugzilla at betaversion dot net
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14004


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]