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

std::basic_ios::rdstate

性病:基本[医]IOS::rdstate

iostate rdstate() const;

返回当前流错误状态。

参数

%280%29

返回值

当前流错误状态。它是位掩码类型,可以是以下常量的组合:

ConstantExplanation
goodbitno error
badbitirrecoverable stream error
failbitinput/output operation failed (formatting or extraction error)
eofbitassociated input sequence has reached end-of-file

二次

#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 // check state is exactly eofbit (no failbit and no badbit) if (stream.rdstate() == std::ios_base::eofbit) { std::cout << "stream state is eofbit\n"; } }

二次

产出:

二次

stream state is goodbit stream state is eofbit

二次

另见

setstatesets 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/rdstate