This is the mail archive of the
libstdc++@sources.redhat.com
mailing list for the libstdc++ project.
bug ofstream and ios::trunc
- To: stdc++ <libstdc++ at sourceware dot cygnus dot com>
- Subject: bug ofstream and ios::trunc
- From: peeterj at ca dot ibm dot com
- Date: Wed, 27 Sep 2000 00:01:44 -0400
Hi,
Using both gcc-2.95.2/lib/gcc-lib/powerpc-ibm-aix4.3.2.0 and
i386-redhat-linux/egcs-2.91.66 I am seeing that when ios::trunc is
specified in the ofstream constructor mode parameter, no output is ever
generated, as the following small samples illustrate.
/* no_output.cc */
#include <fstream.h>
int main()
{
ofstream f("blah", ios::trunc);
f << "hi\n";
return 0;
}
vs.
/* gives_output.cc */
#include <fstream.h>
int main()
{
ofstream f("blah");
f << "hi\n";
return 0;
}
It seems that ios::out is not added to the ofstream mode flags if trunc
(and presumably other flags) are used for the mode. This doesn't make much
sense for an ofstream (out by definition), but I am not sure if the
standard says anything about whether this is bad behaviour or not
(emperically, the C++ compilers on at least AIX, Sun, Dynix, HP and NT all
have ofstreams that set ios::out in addition to whatever flags are
specified by the user.)
Peeter