◐ Shell
clean mode source ↗

std::basic_ios<CharT,Traits>::setstate - cppreference.com

提供: cppreference.com

<tbody> </tbody>

void setstate( iostate state );

現在セットされているフラグに追加でストリームのエラーフラグ state をセットします。 実質的に clear(rdstate() | state) を呼びます。 例外を投げるかもしれません。

引数

state - セットするストリームのエラー状態フラグ。 以下の定数を組み合わせることができます。

戻り値

(なし)

#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";
    }
}

出力:

stream is not fail
now stream is fail
and stream is not good

関連項目