closing stream before opening sets fail bit
Rob Willis
robwillis@greenwood.net
Sat Jun 17 16:45:00 GMT 2000
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
More information about the Libstdc++
mailing list