This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: libstdc++/5180: seekp() on fstreams opened in read only mode
- From: paolo at gcc dot gnu dot org
- To: gcc-bugs at gcc dot gnu dot org, gcc-prs at gcc dot gnu dot org, kingleo at gmx dot at, nobody at gcc dot gnu dot org, paolo at gcc dot gnu dot org
- Date: 24 Dec 2001 09:45:56 -0000
- Subject: Re: libstdc++/5180: seekp() on fstreams opened in read only mode
- Reply-to: paolo at gcc dot gnu dot org, gcc-bugs at gcc dot gnu dot org, gcc-prs at gcc dot gnu dot org, kingleo at gmx dot at, nobody at gcc dot gnu dot org, paolo at gcc dot gnu dot org, gcc-gnats at gcc dot gnu dot org
Synopsis: seekp() on fstreams opened in read only mode
Responsible-Changed-From-To: unassigned->paolo
Responsible-Changed-By: paolo
Responsible-Changed-When: Mon Dec 24 01:45:56 2001
Responsible-Changed-Why:
Taking care of it.
State-Changed-From-To: open->feedback
State-Changed-By: paolo
State-Changed-When: Mon Dec 24 01:45:56 2001
State-Changed-Why:
I think the behaviour you are reporting is standard
conforming. In fact, after seekp(0) the failbit is set
and the standard prescribes that all IOStreams operations
have no effect once the stream state indicates an error
situation. Compare the behaviour of the testcase with that
(identical) of:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main( int argc, char** argv )
{
if( argc != 2)
return 1;
fstream in( argv[1], std::ios::in );
if( !in )
{
cout << "cannot open file " << endl;
return 2;
}
/*
in.seekp(0); // <<<<<<<
if (in.rdstate() & ios::failbit)
{
cout << "fail" << endl;
in.clear();
}
*/
while( !in.eof() )
{
string s;
//getline( in, s );
cout << s << endl;;
}
return 0;
};
http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=5180