[istream.sentry] (original) (raw)
31 Input/output library [input.output]
31.7 Formatting and manipulators [iostream.format]
31.7.5 Input streams [input.streams]
31.7.5.2 Class template basic_istream [istream]
31.7.5.2.4 Class basic_istream::sentry [istream.sentry]
namespace std { template<class charT, class traits> class basic_istream<charT, traits>::sentry { bool ok_; public: explicit sentry(basic_istream& is, bool noskipws = false);~sentry();explicit operator bool() const { return ok_; } sentry(const sentry&) = delete; sentry& operator=(const sentry&) = delete;};}
The classsentrydefines a class that is responsible for doing exception safe prefix and suffix operations.
explicit sentry(basic_istream& is, bool noskipws = false);
Effects: Ifis.good()isfalse, calls is.setstate(failbit).
Otherwise, prepares for formatted or unformatted input.
First, ifis.tie()is not a null pointer, the function callsis.tie()->flush()to synchronize the output sequence with any associated external C stream.
Except that this call can be suppressed if the put area ofis.tie()is empty.
Further an implementation is allowed to defer the call toflushuntil a call ofis.rdbuf()->underflow()occurs.
If no such call occurs before thesentryobject is destroyed, the call toflushmay be eliminated entirely.273
If noskipws is zero andis.flags() & ios_base::skipwsis nonzero, the function extracts and discards each character as long as the next available input character c is a whitespace character.
Ifis.rdbuf()->sbumpc()oris.rdbuf()->sgetc()returnstraits::eof(), the function callssetstate(failbit | eofbit)(which may throwios_base::failure).
Remarks: The constructorexplicit sentry(basic_istream& is, bool noskipws = false) uses the currently imbued locale in is, to determine whether the next input character is whitespace or not.
To decide if the character c is a whitespace character, the constructor performs as if it executes the following code fragment:const ctype<charT>& ctype = use_facet<ctype<charT>>(is.getloc());if (ctype.is(ctype.space, c) != 0)
If, after any preparation is completed,is.good()istrue,ok_ != falseotherwise,ok_ == false.
During preparation, the constructor may callsetstate(failbit)(which may throwios_base::failure ([iostate.flags])).274
explicit operator bool() const;