c++/7235: iostream bug: cannot re-read a file.

Andrea Latina latina@to427xl.to.infn.it
Mon Jul 8 11:15:00 GMT 2002


>Number:         7235
>Category:       c++
>Synopsis:       If I open twice a file, I'm not able to read anything from it.
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Jul 08 10:46:00 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     Andrea Latina
>Release:        3.1
>Organization:
>Environment:
System: Linux to427xl.to.infn.it 2.4.18-5smp #1 SMP Mon Jun 10 15:19:40 EDT 2002 i686 unknown
Architecture: i686

	
host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: i686-pc-linux-gnu
configured with: ../gcc-3.1/configure --enable-threads
>Description:
When I close a file previously opened, then I reopen it, I'm not able to read anything from the file. 
>How-To-Repeat:
I report the code exploiting the error:
#include <iostream>
#include <fstream>

using namespace std;

int main()
{
        ifstream file("dati");

        if (file)
        {
                int x, y;

                while(file >> x >> y)	cout << x << '\t' << y << endl;


                file.close();
                file.open("dati");

		// the following line fails!

		while(file >> x >> y)	cout << x << '\t' << y << endl;


        }

        return 0;
}

where "dati" is a ascii file, like this:

10 10
20 20

for example.
>Fix:
	
>Release-Note:
>Audit-Trail:
>Unformatted:



More information about the Gcc-bugs mailing list