Name
basic_ostream::sentry class — Sentry class for output streams
Synopsis
template <class charT,class traits = char_traits<charT> > class basic_ostream<charT,traits>::sentry { public: explicit sentry(basic_ostream<charT,traits>& os); ~sentry( ); operator bool( ) const; private: sentry(const sentry&); // Not defined sentry& operator=(const sentry&); // Not defined };
A basic_ostream
object
constructs a temporary sentry
object prior to each output operation. The sentry object is
destroyed when the output operation finishes and the function
returns. The sentry manages tied streams and unit buffering.
The stream passes itself to the sentry’s constructor. If
stream.good( )
is true
, the sentry first flushes any tied
stream. That is, if stream.tie( )
is not null, the sentry calls stream.tie(
)->flush( )
.
If sentry preparation fails, badbit
is set.
The sentry destructor flushes the buffer if the unitbuf
flag is on and the output function
did not throw an exception:
if ((os.flags( ) & ios_base::unitbuf) && !uncaught_exception( )) os.flush( );
See Also
basic_ostream class
template, basic_ios
in
<ios>
Get C++ In a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.