cpp/io/basic istream/sentry

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

Member functions
{{member|{{small|std::basic_istream::sentry::}}sentry|2= {{ddcl|1= explicit sentry( std::basic_istream& is, bool noskipws = false ); }}

Prepares the stream for formatted input.

If {{c|is.good}} is {{c|false}}, calls {{c|is.setstate(std::ios_base::failbit)}} and returns. Otherwise, if {{c|is.tie}} is not a null pointer, calls {{c|is.tie->flush}} to synchronize the output sequence with external streams. This call can be suppressed if the put area of {{c|is.tie}} is empty. The implementation may defer the call to {{c|flush}} until a call of {{c|is.rdbuf->underflow}} occurs. If no such call occurs before the sentry object is destroyed, it may be eliminated entirely.

If {{c|noskipws}} is zero and {{c|is.flags & std::ios_base::skipws}} is nonzero, the function extracts and discards all whitespace characters until the next available character is not a whitespace character (as determined by the currently imbued locale in {{c|is}}). If {{c|is.rdbuf->sbumpc}} or {{c|is.rdbuf->sgetc}} returns {{c|traits::eof}}, the function calls {{c|setstate(std::ios_base::failbit {{!}} std::ios_base::eofbit)}} (which may throw {{lc|std::ios_base::failure}}).

Additional implementation-defined preparation may take place, which may call {{c|setstate(std::ios_base::failbit)}} (which may throw {{lc|std::ios_base::failure}}).

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

Exceptions
std if the end of file condition occurs when skipping whitespace. }}

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

Parameters
(none)

Return value
if the initialization of the input stream was successful, otherwise. }}