public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/14004] New: seekg/eof problem: reading from a file twice fails
@ 2004-02-03 18:44 jens dot auer-bugzilla at betaversion dot net
  2004-02-03 18:46 ` [Bug libstdc++/14004] " jens dot auer-bugzilla at betaversion dot net
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: jens dot auer-bugzilla at betaversion dot net @ 2004-02-03 18:44 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug libstdc++/14004] seekg/eof problem: reading from a file twice fails
  2004-02-03 18:44 [Bug libstdc++/14004] New: seekg/eof problem: reading from a file twice fails jens dot auer-bugzilla at betaversion dot net
@ 2004-02-03 18:46 ` jens dot auer-bugzilla at betaversion dot net
  2004-02-03 19:06 ` pcarlini at suse dot de
  2004-02-03 19:26 ` jens dot auer at betaversion dot net
  2 siblings, 0 replies; 4+ messages in thread
From: jens dot auer-bugzilla at betaversion dot net @ 2004-02-03 18:46 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From jens dot auer-bugzilla at betaversion dot net  2004-02-03 18:46 -------
Created an attachment (id=5668)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=5668&action=view)
preprocessed output of gcc


-- 


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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug libstdc++/14004] seekg/eof problem: reading from a file twice fails
  2004-02-03 18:44 [Bug libstdc++/14004] New: seekg/eof problem: reading from a file twice fails jens dot auer-bugzilla at betaversion dot net
  2004-02-03 18:46 ` [Bug libstdc++/14004] " jens dot auer-bugzilla at betaversion dot net
@ 2004-02-03 19:06 ` pcarlini at suse dot de
  2004-02-03 19:26 ` jens dot auer at betaversion dot net
  2 siblings, 0 replies; 4+ messages in thread
From: pcarlini at suse dot de @ 2004-02-03 19:06 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pcarlini at suse dot de  2004-02-03 19:06 -------
Not a bug. This is the correct behavior, mandated by the standard which is now
tracked *much* more closely than before (in particolar iostreams have been
*completely* rewritten for gcc3.x)

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug libstdc++/14004] seekg/eof problem: reading from a file twice fails
  2004-02-03 18:44 [Bug libstdc++/14004] New: seekg/eof problem: reading from a file twice fails jens dot auer-bugzilla at betaversion dot net
  2004-02-03 18:46 ` [Bug libstdc++/14004] " jens dot auer-bugzilla at betaversion dot net
  2004-02-03 19:06 ` pcarlini at suse dot de
@ 2004-02-03 19:26 ` jens dot auer at betaversion dot net
  2 siblings, 0 replies; 4+ messages in thread
From: jens dot auer at betaversion dot net @ 2004-02-03 19:26 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From jens dot auer at betaversion dot net  2004-02-03 19:26 -------
Subject: Re:  seekg/eof problem: reading from a file
 twice fails

On 3 Feb 2004 19:06:12 -0000
"pcarlini at suse dot de" <gcc-bugzilla@gcc.gnu.org> wrote:

> ------- Additional Comments From pcarlini at suse dot de  2004-02-03
> 19:06 ------- Not a bug. This is the correct behavior, mandated by the
> standard which is now tracked *much* more closely than before (in
> particolar iostreams have been*completely* rewritten for gcc3.x)

Thank you for your fast answer.
Is it also not a bug when I call clear() after seekg()? The eof-bit gets
set to 0, but reading still doesn`t work.

Regards
  Jens


-- 


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


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2004-02-03 19:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-02-03 18:44 [Bug libstdc++/14004] New: seekg/eof problem: reading from a file twice fails jens dot auer-bugzilla at betaversion dot net
2004-02-03 18:46 ` [Bug libstdc++/14004] " jens dot auer-bugzilla at betaversion dot net
2004-02-03 19:06 ` pcarlini at suse dot de
2004-02-03 19:26 ` jens dot auer at betaversion dot net

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).