std::basic_ios<CharT,Traits>:: rdstate
From cppreference.net
C++
Input/output library
| I/O manipulators | ||||
| Print functions (C++23) | ||||
| C-style I/O | ||||
| Buffers | ||||
|
(C++23)
|
||||
|
(
C++98/26*
)
|
||||
|
(C++20)
|
||||
| Streams | ||||
| Abstractions | ||||
| File I/O | ||||
| String I/O | ||||
| Array I/O | ||||
|
(C++23)
|
||||
|
(C++23)
|
||||
|
(C++23)
|
||||
|
(
C++98/26*
)
|
||||
|
(
C++98/26*
)
|
||||
|
(
C++98/26*
)
|
||||
| Synchronized Output | ||||
|
(C++20)
|
||||
| Types | ||||
| Error category interface | ||||
|
(C++11)
|
||||
|
(C++11)
|
std::basic_ios
| Member functions | ||||
| State functions | ||||
|
basic_ios::rdstate
|
||||
| Formatting | ||||
| Miscellaneous | ||||
| Protected member functions | ||||
|
(C++11)
|
||||
|
(C++11)
|
||||
|
(C++11)
|
|
iostate rdstate
(
)
const
;
|
||
返回当前流错误状态。
目录 |
参数
(无)
返回值
当前流错误状态。它是一个位掩码类型,可以是以下常量的组合:
| 常量 | 说明 |
| goodbit | 无错误 |
| badbit | 不可恢复的流错误 |
| failbit | 输入/输出操作失败(格式化或提取错误) |
| eofbit | 关联的输入序列已到达文件结尾 |
示例
运行此代码
#include <iostream> #include <sstream> int main() { std::ostringstream stream; if (stream.rdstate()== std::ios_base::goodbit) std::cout << "stream state is goodbit\n"; stream.setstate(std::ios_base::eofbit); // 检查状态恰好为 eofbit(无 failbit 且无 badbit) if (stream.rdstate() == std::ios_base::eofbit) std::cout << "stream state is eofbit\n"; }
输出:
stream state is goodbit stream state is eofbit
参见
|
设置状态标志
(公开成员函数) |
|
|
修改状态标志
(公开成员函数) |