C++ Logo

std-discussion

Advanced search

Re: Setting badbit when outputting to an unopened fstream in eof state

From: Gennaro Prota <gennaro.prota_at_[hidden]>
Date: Thu, 7 Nov 2019 11:52:05 +0100
On Sun, Nov 3, 2019 at 9:23 PM Gennaro Prota <gennaro.prota_at_[hidden]> wrote:
>
> { 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?

Since, differently from other questions, I didn't get any reply, I
wonder: was this question off-topic? In fact, I didn't find any page
explaining what is on topic and what is not for this list, so I just
"went intuitively", so to speak. Sorry for that.

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

Received on 2019-11-07 04:55:01