std::basic_ios<CharT,Traits>::setstate
来自cppreference.com
输入/输出库
std::basic_ios
| 成员函数 | ||||
| 状态函数 | ||||
|
basic_ios::setstate
|
||||
| 格式化 | ||||
| 杂项 | ||||
| 受保护成员函数 | ||||
|
(C++11)
|
||||
|
(C++11)
|
||||
|
(C++11)
|
|
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
参阅
| 返回状态标志 (公开成员函数) |
|
| 修改状态标志 (公开成员函数) |