C++ Logo

STD-DISCUSSION

Advanced search

Subject: Setting badbit when outputting to an unopened fstream in eof state
From: Gennaro Prota (gennaro.prota_at_[hidden])
Date: 2019-11-03 14:23:53


{ Resending this, as it was apparently lost. }

Hi,

this program:

  #include <fstream>
  #include <iostream>

  int
  main()
  {
      std::fstream fs ;
      fs.clear( std::ios_base::eofbit ) ;

      fs << "this isn't actually output" ;

      if ( ( fs.rdstate() & std::ios_base::badbit ) != 0 ) {
          std::cout << "badbit set" << std::endl ;
      }
  }

prints "badbit set" on Visual C++ 2015 and prints nothing with GCC or
Clang+libstdc++.

Does the standard allow both behaviors?

--
--
.:: Gennaro Prota ::.
.:: https://about.me/gennaro.prota ::.


STD-DISCUSSION list run by std-discussion-owner@lists.isocpp.org

Older Archives on Google Groups