std::ios_base| Member functions |
|
|
|
| Formatting |
|
|
|
|
|
| Locales |
|
|
| Internal extensible array |
|
|
|
| Miscellaneous |
|
|
| Member classes |
|
|
| Member types |
|
|
|
|
|
|
typedef/*implementation defined*/ iostate; | | |
staticconstexpr iostate goodbit=0; | | |
staticconstexpr iostate badbit =/* implementation defined */
staticconstexpr iostate failbit=/* implementation defined */
staticconstexpr iostate eofbit =/* implementation defined */ | | |
| | |
Specifies stream state flags. It is aBitmaskType, the following constants are defined:
| Constant | Explanation |
| goodbit | no error |
| badbit | irrecoverable stream error |
| failbit | input/output operation failed (formatting or extraction error) |
| eofbit | associated input sequence has reached end-of-file |
[edit]The eofbit
The eofbit is set by the following standard library functions:
- The string input functionstd::getline if it completes by reaching the end of the stream, as opposed to reaching the specified terminating character.
- The numeric input overloads ofbasic_istream::operator>> if the end of the stream was encountered while reading the next character, on Stage 2 ofnum_get::get processing. Depending on the parsing state,
failbit may or may not be set at the same time: for example,int n; istringstream buf("1"); buf>> n; setseofbit, but notfailbit: the integer1 was successfully parsed and stored inn. On the other hand,bool b; istringstream buf("tr"); buf>> boolalpha>> b; sets botheofbit andfailbit: there was not enough characters to complete the parsing of the booleantrue. - The character extraction overloads ofoperator>>std::basic_istream, if the end of the stream is reached before the limit (if any) on the number of characters to be extracted.
- Thestd::get_time I/O manipulator and any of thestd::time_get parsing functions:time_get::get,time_get::get_time,time_get::get_date, etc., if the end of the stream is reached before the last character needed to parse the expected date/time value was processed.
- Thestd::get_money I/O manipulator andmoney_get::get function, if the end of the stream is reached before the last character needed to parse the expected monetary value was processed.
- Thebasic_istream::sentry constructor, executed at the beginning of every formatted input function: unless the
skipws bit is unset (e.g. by issuingstd::noskipws), sentry reads and discards the leading whitespace characters. If the end of the input stream is reached during this operation, botheofbit andfailbit are set, and no input takes place. - The I/O manipulatorstd::ws, if it reaches the end of the stream while consuming whitespace (but, unlike the formatted input sentry, it does not set
failbit in this case). - The unformatted input functionsbasic_istream::read,basic_istream::get,basic_istream::peek,basic_istream::readsome,basic_istream::ignore, andbasic_istream::getline, when reaching the end of the stream.
- The discard input functionbasic_istream::ignore, when reaching the end of the stream before reaching the specified delimiter character.
- The immediate input functionbasic_istream::readsome, ifbasic_streambuf::in_avail returns-1.
The following functions cleareofbit as a side-effect:
Note that in nearly all situations, if eofbit is set, the failbit is set as well.
[edit]The failbit
The failbit is set by the following standard library functions:
- Thebasic_istream::sentry constructor, executed at the beginning of every input function, if either
eofbit orbadbit is already set on the stream, or if the end of stream is encountered while consuming leading whitespace. - Thebasic_ostream::sentry constructor, executed at the beginning of every output function, under implementation-defined conditions.
- operator>>(std::basic_string<>) if the function extracts no characters from the input stream.
- operator>>(std::complex<>) if the function fails to extract a valid complex number.
- The character array and single character overloads ofoperator>> if they fail to extract any characters.
- The streambuf overload ofbasic_istream::operator>> if the streambuf argument is a null pointer or if no characters were inserted into the streambuf.
- The streambuf overload ofbasic_ostream::operator<< if the function inserts no characters.
- operator>>(std::bitset<>) if the function extracts no characters from the input stream.
- std::getline if the function extracts no characters or if it manages to extractbasic_string::max_size characters from the input stream.
- The numeric, pointer, and boolean input overloads ofbasic_istream::operator>> (technically, the overloads ofnum_get::get they call), if the input cannot be parsed as a valid value or if the value parsed does not fit in the destination type.
- The time input manipulatorstd::get_time (technically,time_get::get it calls), if the input cannot be unambiguously parsed as a time value according to the given format string.
- The currency input manipulatorstd::get_money (technically,money_get::get it calls), if the input cannot be unambiguously parsed as a monetary value according to the locale rules.
- The extraction operators of allRandomNumberEngines, if bad input is encountered.
- The extraction operators of allRandomNumberDistributions, if bad input is encountered.
- The unformatted input functionsbasic_istream::get if they fails to extract any characters.
- basic_istream::getline, if it extracts no characters, if it fills in the provided buffer without encountering the delimiter, or if the provided buffer size is less than 1.
- basic_istream::read, if the end-of-file condition occurs on the input stream before all requested characters could be extracted.
- basic_istream::seekg on failure
- basic_ostream::tellp on failure
- The constructors ofstd::basic_fstream,std::basic_ifstream, andstd::basic_ofstream that takes a filename argument, if the file cannot be opened.
- basic_fstream::open,basic_ifstream::open, andbasic_ofstream::open if the file cannot be opened.
- basic_fstream::close,basic_ifstream::close, andbasic_ofstream::close if the file cannot be closed.
[edit]The badbit
The badbit is set by the following standard library functions:
- basic_ostream::put if it fails to insert a character into the output stream, for any reason.
- basic_ostream::write if it fails to insert a character into the output stream, for any reason.
- Formatted output functionsoperator<<,std::put_money, andstd::put_time, if they encounter the end of the output stream before completing output.
- basic_ios::init when called to initialize a stream with a null pointer for
rdbuf(). - basic_istream::putback andbasic_istream::unget when called on a stream with a null
rdbuf(). - basic_ostream::operator<<(basic_streambuf*) when a null pointer is passed as the argument.
- basic_istream::putback andbasic_istream::unget ifrdbuf()->sputbackc() orrdbuf()->sungetc() returntraits::eof().
- basic_istream::sync,basic_ostream::flush, and every output function on a
unitbuf output stream, ifrdbuf()->pubsync() returns-1. - Every stream I/O function if an exception is thrown by any member function of the associated stream buffer (e.g.
sbumpc(),xsputn(),sgetc(),overflow(), etc). - ios_base::iword andios_base::pword on failure (e.g. failure to allocate memory).
[edit]Example
| This section is incomplete Reason: no example |
[edit]See also
The following table shows the value ofbasic_ios accessors (good(),fail(), etc.) for all possible combinations ofios_base::iostate flags:
| ios_base::iostate flags | basic_ios accessors |
eofbit | failbit | badbit | good() | fail() | bad() | eof() | operator bool | operator! |
| false | false | false | true | false | false | false | true | false |
| false | false | true | false | true | true | false | false | true |
| false | true | false | false | true | false | false | false | true |
| false | true | true | false | true | true | false | false | true |
| true | false | false | false | false | false | true | true | false |
| true | false | true | false | true | true | true | false | true |
| true | true | false | false | true | false | true | false | true |
| true | true | true | false | true | true | true | false | true |
| returns state flags (public member function ofstd::basic_ios<CharT,Traits>)[edit] |
| sets state flags (public member function ofstd::basic_ios<CharT,Traits>)[edit] |
| modifies state flags (public member function ofstd::basic_ios<CharT,Traits>)[edit] |