cpp/io/basic ostream/sentry

An object of class is constructed in local scope at the beginning of each member function of std that performs output (both formatted and unformatted). Its constructor prepares the output stream: checks if the stream is already in a failed state, flushes the tie'd output streams, and performs other implementation-defined tasks if necessary. Implementation-defined cleanup, as well as flushing of the output stream if necessary, is performed in the destructor, so that it is guaranteed to happen if exceptions are thrown during output.

Member functions
{{member|{{small|std::basic_ostream::sentry::}}sentry| 2= {{ddcl|1= explicit sentry( std::basic_ostream& os ); }}

Prepares the stream for formatted output.

If {{c|os.good}} is {{c|false}}, returns. Otherwise, if {{c|os.tie}} is not a null pointer, calls {{c|os.tie->flush}} to synchronize the output sequence with external streams. During preparation, the constructor may call {{c|setstate(failbit)}} (which may throw {{lc|std::ios_base::failure}}).

If after preparation is completed, {{c|1=os.good == true}}, then any subsequent calls to {{c/core|operator bool}} will return {{c|true}}.

Exceptions
std if the end of file condition occurs. }}

{{member|{{small|std::basic_ostream::sentry::}}operator bool|2= {{ddcl|1= explicit operator bool const; }} Checks whether the preparation of the output stream was successful.

Parameters
(none)

Return value
if the preparation of the output stream was successful, otherwise. }}