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-file | 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 |
---|---|---|---|---|---|---|---|---|---|---|---|---|
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 |
返回值
%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';
}
二次
另见
setstate | sets state flags (public member function) |
---|---|
rdstate | returns state flags (public member function) |
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。