C++ ios 库 - rdstate
描述
它用于检查获取错误状态标志。 内部错误状态标志是通过调用流上的输入/输出函数自动设置的,以发出某些错误的信号。
声明
以下是 ios::rdstate 函数的声明。
iostate rdstate() const;
参数
none
返回值
可以包含以下状态标志成员常量的任意组合的 ios_base::iostate 类型的对象 −
iostate value (member constant) |
indicates | functions to check state flags | ||||
|---|---|---|---|---|---|---|
| good() | eof() | fail() | bad() | rdstate() | ||
| goodbit | No errors (zero value iostate) | true |
false |
false |
false |
goodbit |
| eofbit | End-of-File reached on input operation | false |
true |
false |
false |
eofbit |
| failbit | Logical error on i/o operation | false |
false |
true |
false |
failbit |
| badbit | Read/writing error on i/o operation | false |
false |
true |
true |
badbit |
异常
Strong guarantee − 如果抛出异常,则流中没有变化。
数据竞争
访问流对象。
对同一流对象的并发访问可能会导致数据竞争。
示例
在下面的示例中显示了 ios::rdstate。
#include <iostream>
#include <fstream>
int main () {
std::ifstream is;
is.open ("test.txt");
if ( (is.rdstate() & std::ifstream::failbit ) != 0 )
std::cerr << "Error opening 'test.txt'\n";
return 0;
}

