This is the mail archive of the libstdc++@sourceware.cygnus.com mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

closing stream before opening sets fail bit




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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]