Copied from the answer by Andreas Papadopoulos to a slightly different question - be sure to support him there!
Of course you can ( example here ):
int main() { std::clog << "First message" << std::endl; std::clog.setstate(std::ios_base::failbit); std::clog << "Second message" << std::endl; std::clog.clear(); std::clog << "Last message" << std::endl; return 0; }
Outputs:
First message Last message
This is due to the fact that transferring the stream to the fail state will cause it to silently discard any output until bit bit is cleared.
Quentin
source share