std::basic_ios<CharT,Traits>::setstate
void setstate( iostate state ); |
||
在当前已设置表之外,设置流错误状态标志 state
。实质上调用 clear(rdstate() | state) 。可能抛出异常。
参数
state | - | 要设置的流错误状态标志。能为下列常量的组合:
|
返回值
(无)
示例
运行此代码
#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
参阅
返回状态标志 (公开成员函数) | |
修改状态标志 (公开成员函数) |