[edit]Requirements
AFormattedInputFunction is a stream input function that performs the following:
- Constructs an object of typebasic_istream::sentry with automatic storage duration and with the
noskipws
argument set tofalse, which performs the following:
- ifeofbit orbadbit are set on the input stream, sets the
failbit
as well, and if exceptions onfailbit
are enabled in this input stream'sexception mask ((exceptions()& failbit)!=0), throwsios_base::failure. - flushes the tie()'d output stream, if applicable.
- if
ios_base::skipws
flag is set on this input stream, extracts and discards characters from the input stream until one of the following becomes true:
- the next available character on the input stream is not a whitespace character, as tested by thestd::ctype facet of the locale currently imbued in this input stream. The non-whitespace character is not extracted.
- the end of the stream is reached, in which case
failbit
andeofbit
are set and if the stream is on for exceptions on one of these bits,ios_base::failure is thrown.
- Checks the status of the sentry by calling
sentry::operator bool()
, which is equivalent tobasic_ios::good. - If the sentry returnedfalse or sentry's constructor threw an exception, no input takes place.
- If the sentry returnedtrue, performs the input as if by callingrdbuf()->sbumpc() orrdbuf()->sgetc().
- if the end of the stream is reached (the call tordbuf()->sbumpc() orrdbuf()->sgetc() returnsTraits::eof()), sets
eofbit
. If exceptions oneofbit
are enabled in this stream'sexception mask ((exceptions()& eofbit)!=0), throwsios_base::failure. - if an exception is thrown during input, sets
badbit
in the input stream. If exceptions onbadbit
are enabled in this stream'sexception mask ((exceptions()& badbit)!=0), the exception is also rethrown. - If no exception was thrown, returns*this.
- In any event, whether terminating by exception or returning, the sentry's destructor is called before leaving this function.
[edit]Standard library
The following standard library functions areFormattedInputFunctions.
[edit]Defect reports
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
DR | Applied to | Behavior as published | Correct behavior |
---|
LWG 160 | C++98 | the process of determining whether the exception caught is rethrown mentioned a non-existing functionexception() | corrected toexceptions() |