std::basic_ios::rdstate
iostate rdstate() const;  |   |   | 
|---|
返回当前流错误状态。
参数
%280%29
返回值
当前流错误状态。它是位掩码类型,可以是以下常量的组合:
Constant  | Explanation  | 
|---|---|
goodbit  | no error  | 
badbit  | irrecoverable stream error  | 
failbit  | input/output operation failed (formatting or extraction error)  | 
eofbit  | associated 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二次
另见
setstate  | sets state flags (public member function)  | 
|---|---|
clear  | clears error and eof flags (public member function)  | 
 © cppreference.com在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com

