std::basic_ios::setstate
性病:基本[医]监督办::setstate
void setstate( iostate state | | |
---|
设置流错误标志state
除了当前设置的标志。本质上是呼叫clear(rdstate() | state)
可能会抛出异常。
参数
state | - | stream error state flags to set. It can be a combination of the following constants: 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 | 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 |
---|---|---|---|---|---|---|---|---|---|---|---|---|
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 |
返回值
%280%29
例
二次
#include <iostream>
#include <sstream>
int main()
{
std::ostringstream stream;
if (!stream.fail()) {
std::cout << "stream is not fail\n";
}
stream.setstate(std::ios_base::failbit
if (stream.fail()) {
std::cout << "now stream is fail\n";
}
if (!stream.good()) {
std::cout << "and stream is not good\n";
}
}
二次
产出:
二次
stream is not fail
now stream is fail
and stream is not good
二次
另见
rdstate | returns state flags (public member function) |
---|---|
clear | clears error and eof flags (public member function) |
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。