std::ios_base::iostate(3)
π std::ios_base::iostate π
okay bestie, welcome to the C++ Standard Libary manual, section 3 β yes, that's how it's spelled in the header, and honestly? iconic typo energy π. This page is literally about std::ios_base::iostate, and we're gonna get into it β¨
πΈ NAME πΈ
std::ios_base::iostate β yeah, it's std::ios_base::iostate. That's the name. Periodt π
β¨ Synopsis β¨
typedef /*implementation defined*/ iostate;
static constexpr iostate goodbit = 0;
static constexpr iostate badbit = /* implementation defined */
static constexpr iostate failbit = /* implementation defined */
static constexpr iostate eofbit = /* implementation defined */
Specifies stream state flags. It is a BitmaskType, and the following constants are defined:
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 π¦
π¦ The eofbit π¦
The eofbit is set by the following standard library functions:
- The string input function
std::getlineif it completes by reaching the end of the stream, as opposed to reaching the specified terminating character. - The numeric input overloads of
basic_istream::operator>>if the end of the stream was encountered while reading the next character, on Stage 2 ofnum_get::getprocessing. Depending on the parsing state,failbitmay or may not be set at the same time: for example,int n; istringstream buf("1"); buf >> n;setseofbit, but notfailbit: the integer1was successfully parsed and stored inn. On the other hand,bool b; istringstream buf("tr"); buf >> boolalpha >> b;sets botheofbitandfailbit: there was not enough characters to complete the parsing of the booleantrue. - The character extraction overloads of
operator>>onstd::basic_istream, if the end of the stream is reached before the limit (if any) on the number of characters to be extracted. - The
std::get_timeI/O manipulator and any of thestd::time_getparsing 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. - The
std::get_moneyI/O manipulator andmoney_get::getfunction, if the end of the stream is reached before the last character needed to parse the expected monetary value was processed. - The
basic_istream::sentryconstructor, executed at the beginning of every formatted input function: unless theskipwsbit 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, botheofbitandfailbitare set, and no input takes place. - The I/O manipulator
std::ws, if it reaches the end of the stream while consuming whitespace (but, unlike the formatted input sentry, it does not setfailbitin this case). - The unformatted input functions
basic_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 function
basic_istream::ignore, when reaching the end of the stream before reaching the specified delimiter character. - The immediate input function
basic_istream::readsome, ifbasic_streambuf::in_availreturns-1.
The following functions clear eofbit as a side-effect:
basic_istream::putbackbasic_istream::ungetbasic_istream::seekg
Note that in nearly all situations, if eofbit is set, the failbit is set as well.
π The failbit π
The failbit is set by the following standard library functions:
- The
basic_istream::sentryconstructor, executed at the beginning of every input function, if eithereofbitorbadbitis already set on the stream, or if the end of stream is encountered while consuming leading whitespace. - The
basic_ostream::sentryconstructor, 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 of
operator>>if they fail to extract any characters. - The streambuf overload of
basic_istream::operator>>if the streambuf argument is a null pointer or if no characters were inserted into the streambuf. - The streambuf overload of
basic_ostream::operator<<if the function inserts no characters. operator>>(std::bitset<>)if the function extracts no characters from the input stream.std::getlineif the function extracts no characters or if it manages to extractbasic_string::max_sizecharacters from the input stream.- The numeric, pointer, and boolean input overloads of
basic_istream::operator>>(technically, the overloads ofnum_get::getthey 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 manipulator
std::get_time(technically,time_get::getit calls), if the input cannot be unambiguously parsed as a time value according to the given format string. - The currency input manipulator
std::get_money(technically,money_get::getit calls), if the input cannot be unambiguously parsed as a monetary value according to the locale rules. - The extraction operators of all
RandomNumberEngines, if bad input is encountered. - The extraction operators of all
RandomNumberDistributions, if bad input is encountered. - The unformatted input functions
basic_istream::getif they fail 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 than1.basic_istream::read, if the end-of-file condition occurs on the input stream before all requested characters could be extracted.basic_istream::seekgon failurebasic_ostream::tellpon failure- The constructors of
std::basic_fstream,std::basic_ifstream, andstd::basic_ofstreamthat takes a filename argument, if the file cannot be opened. basic_fstream::open,basic_ifstream::open, andbasic_ofstream::openif the file cannot be opened.basic_fstream::close,basic_ifstream::close, andbasic_ofstream::closeif the file cannot be closed.
π The badbit π
The badbit is set by the following standard library functions:
basic_ostream::putif it fails to insert a character into the output stream, for any reason.basic_ostream::writeif it fails to insert a character into the output stream, for any reason.- Formatted output functions
operator<<,std::put_money, andstd::put_time, if they encounter the end of the output stream before completing output. basic_ios::initwhen called to initialize a stream with a null pointer forrdbuf().basic_istream::putbackandbasic_istream::ungetwhen called on a stream with a nullrdbuf().basic_ostream::operator<<(basic_streambuf*)when a null pointer is passed as the argument.basic_istream::putbackandbasic_istream::ungetifrdbuf()->sputbackc()orrdbuf()->sungetc()returntraits::eof().basic_istream::sync,basic_ostream::flush, and every output function on aunitbufoutput 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::iwordandios_base::pwordon failure (e.g. failure to allocate memory).
π Example π
This section is incomplete Reason: no example
π See also π
The following list shows the value of basic_ios accessors (good(), fail(), etc.) for all possible combinations of ios_base::iostate flags. Columns, in order, are: eofbit, failbit, badbit, good(), fail(), bad(), eof(), operator bool, operator!.
eofbit=false,failbit=false,badbit=falseβgood()=true,fail()=false,bad()=false,eof()=false,operator bool=true,operator!=falseeofbit=false,failbit=false,badbit=trueβgood()=false,fail()=true,bad()=true,eof()=false,operator bool=false,operator!=trueeofbit=false,failbit=true,badbit=falseβgood()=false,fail()=true,bad()=false,eof()=false,operator bool=false,operator!=trueeofbit=false,failbit=true,badbit=trueβgood()=false,fail()=true,bad()=true,eof()=false,operator bool=false,operator!=trueeofbit=true,failbit=false,badbit=falseβgood()=false,fail()=false,bad()=false,eof()=true,operator bool=true,operator!=falseeofbit=true,failbit=false,badbit=trueβgood()=false,fail()=true,bad()=true,eof()=true,operator bool=false,operator!=trueeofbit=true,failbit=true,badbit=falseβgood()=false,fail()=true,bad()=false,eof()=true,operator bool=false,operator!=trueeofbit=true,failbit=true,badbit=trueβgood()=false,fail()=true,bad()=true,eof()=true,operator bool=false,operator!=truerdstateβ returns state flags (public member function ofstd::basic_ios<CharT,Traits>)setstateβ sets state flags (public member function ofstd::basic_ios<CharT,Traits>)clearβ modifies state flags (public member function ofstd::basic_ios<CharT,Traits>)
π Category π
Todo no example
Source/version: http://cppreference.com Β· date: 2024.06.10 Β· page: std::ios_base::iostate(3). Bye bestie, go check your stream state πβ¨
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms