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

std::basic_ios::clear

性病:基本[医]监督办::清空

void clear( std::ios_base::iostate state = std::ios_base::goodbit

的值来设置流错误状态标志。state默认情况下,分配STD::IOS[医]基本:好位,具有清除所有错误状态标志的效果。

如果rdbuf() == 0然后state | badbit被分配了。可能会引发异常。

参数

state-new error state flags setting. It can be a combination of the following constants: 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-fileConstantExplanationgoodbitno errorbadbitirrecoverable stream errorfailbitinput/output operation failed (formatting or extraction error)eofbitassociated input sequence has reached end-of-file
ConstantExplanation
goodbitno error
badbitirrecoverable stream error
failbitinput/output operation failed (formatting or extraction error)
eofbitassociated input sequence has reached end-of-file

返回值

%280%29

例外

如果没有参数,则清除%28%29可用于在意外输入后取消设置故障位。

二次

#include <iostream> #include <string> int main() { double n; while( std::cout << "Please, enter a number\n" && ! (std::cin >> n) ) { std::cin.clear( std::string line; std::getline(std::cin, line std::cout << "I am sorry, but '" << line << "' is not a number\n"; } std::cout << "Thank you for entering the number " << n << '\n'; }

二次

另见

setstatesets state flags (public member function)
rdstatereturns state flags (public member function)

© cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

http://en.cppreference.com/w/cpp/io/basic[医]监督办/清除