首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

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可用于在意外输入后取消设置故障位。

二次

代码语言:javascript
复制
#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)

代码语言:txt
复制
 ? cppreference.com

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

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com