This is the mail archive of the
gcc-prs@gcc.gnu.org
mailing list for the GCC project.
Re: libstdc++/5629: fstream class is unable to create file in a read/write mode
- From: paolo at gcc dot gnu dot org
- To: apakhomov at secant dot com, gcc-bugs at gcc dot gnu dot org, gcc-prs at gcc dot gnu dot org, paolo at gcc dot gnu dot org
- Date: 7 Feb 2002 23:35:50 -0000
- Subject: Re: libstdc++/5629: fstream class is unable to create file in a read/write mode
- Reply-to: paolo at gcc dot gnu dot org, apakhomov at secant dot com, gcc-bugs at gcc dot gnu dot org, gcc-prs at gcc dot gnu dot org, paolo at gcc dot gnu dot org, gcc-gnats at gcc dot gnu dot org
Synopsis: fstream class is unable to create file in a read/write mode
State-Changed-From-To: feedback->closed
State-Changed-By: paolo
State-Changed-When: Thu Feb 7 15:35:50 2002
State-Changed-Why:
Not a bug. v3's iostreams are much more conforming to the
standard and according to the latter in|out corresponds
to C's "r+" (i.e., file *must* exist). Use open mode out
to create the file. That is:
#include <fstream>
#include <unistd.h>
using namespace std;
int main()
{
char text[256];
fstream* fs = new fstream("test.tmp",ios::out);
strcpy(text,"This is a test\n");
fs->write(text,strlen(text));
fs->close();
delete fs;
}
P.S. For further details see, f.i., Josuttis, p 631-634.
http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=5629