In C++, each stream has a bad bit:
This flag is set by operations performed on the stream when an error occurs while read or writing data
According to cppreference.com :
The standard library sets badbit in the following situations:
Insertion into the output stream by
put()orwrite()fails for any reason.Insertion into the output stream by
operator<<,std::put_moneyorstd::put_time, could not complete because the end of the output stream was reached (The facet's formatting output function such asnum_put::put()ormoney_put::put(), returns an iteratoritersuch thatiter.failed()==true)Stream is constructed with a null pointer for
rdbuf(), orputback()/unget()is called on a stream with a nullrdbuf(), or a null pointer passed tooperator<<(basic_streambuf*)
rdbuf()->sputbackc()orrdbuf()->sungetc()returntraits::eof()toputback() orunget()`
rdbuf()->pubsync()returns -1 tosync(), toflush(), or to the destructor ofostream::sentryon aunitbufstreamException is thrown during an I/O operation by any member function of the associated stream buffer (e.g.
sbumpc(),xsputn(),sgetc(),overflow(), etc)Exception is thrown in
iword()orpword()(e.g.std::bad_alloc)
This may be one more reason to choose cppreference.com over www.cpluplus.com, see: What's wrong with cplusplus.com?