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

std::basic_ios::setstate

void setstate( iostate state );

?

?

设置流错误标志state除了当前设置的标志。本质上是呼叫clear(rdstate() | state)可能会抛出异常。

参数

state

-

stream error state flags to set. 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

二次

代码语言:javascript
复制
#include <iostream>
#include <sstream>
 
int main()
{
    std::ostringstream stream;
 
    if (!stream.fail()) {
        std::cout << "stream is not fail\n";
    }
 
    stream.setstate(std::ios_base::failbit);
 
    if (stream.fail()) {
        std::cout << "now stream is fail\n";
    }
 
    if (!stream.good()) {
        std::cout << "and stream is not good\n";
    }
}

二次

产出:

二次

代码语言:javascript
复制
stream is not fail
now stream is fail
and stream is not good

二次

另见

rdstate

returns state flags (public member function)

clear

clears error and eof flags (public member function)

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

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

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com