This is the mail archive of the
libstdc++@sourceware.cygnus.com
mailing list for the libstdc++ project.
closing stream before opening sets fail bit
- To: <libstdc++ at sourceware dot cygnus dot com>
- Subject: closing stream before opening sets fail bit
- From: "Rob Willis" <robwillis at greenwood dot net>
- Date: Sat, 17 Jun 2000 16:38:47 -0700
Found this quirky behavior. Is this the correct behavior? Basically, calling
close() before opening the ofstream causes the fail bit to be
set. I can live with that... But then, the open command succeeds and the
fail bit is still set!! And of course the write fails.
Try this sample:
(i'm using the egcs-20000612 image of both gcc and libstdc++-v3)
#include <fstream>
#include <iostream>
int main()
{
std::ofstream ofs1;
ofs1.close();
// false as expected:
std::cout << ofs1.is_open() << std::endl;
// this is now true:
std::cout << !(ofs1) << std::endl;
ofs1.open( "junk.tmp" );
// is_open is now true !?!
std::cout << ofs1.is_open() << std::endl;
// fail bit still true
std::cout << !(ofs1) << std::endl;
// this fails...
ofs1 << "junk" << std::endl;
}
--
Rob Willis
rob@e-critical.com
760-822-1439