C++ Logo

std-discussion

Advanced search

Setting badbit when outputting to an unopened fstream in eof state

From: Gennaro Prota <gennaro.prota_at_[hidden]>
Date: Sun, 3 Nov 2019 21:23:53 +0100
{ 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 ::.

Received on 2019-11-03 14:26:24