Can std::cout
set the badbit
or failbit
with the operator <<
. If so, when does this occur?
std::cout
maps to lower-level OS facilities, and anything that could make the OS fail its write will show up as failbit
or badbit
. For example, on Linux, you can cause this to happen by closing stdout:
int main(int argc, char* argv[])
{
close(1);
std::cout << "Hello, world!" << std::endl;
return cout.fail(); // returns 1
}
(And, because file descriptors are inherited, your calling process may have closed stdout for you.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With