在线文档教程
C++
输入/输出 | Input/output

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-fileConstantExplanationgoodbitno errorbadbitirrecoverable stream errorfailbitinput/output operation failed (formatting or extraction error)eofbitassociated input sequence has reached end-of-file
ConstantExplanation
goodbitno error
badbitirrecoverable stream error
failbitinput/output operation failed (formatting or extraction error)
eofbitassociated 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

二次

另见

rdstatereturns state flags (public member function)
clearclears error and eof flags (public member function)

© cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

http://en.cppreference.com/w/cpp/io/basic[医]IOS/setstate