Namespaces
Variants

std::basic_ios<CharT,Traits>:: setstate

From cppreference.net
void setstate ( iostate state ) ;

스트림 오류 플래그 state 를 현재 설정된 플래그에 추가로 설정합니다. 기본적으로 clear ( rdstate ( ) | state ) 를 호출합니다. 예외를 발생시킬 수 있습니다.

목차

매개변수

state - 설정할 스트림 오류 상태 플래그. 다음 상수들의 조합일 수 있습니다:
상수 설명
goodbit 오류 없음
badbit 복구 불가능한 스트림 오류
failbit 입출력 작업 실패 (형식화 또는 추출 오류)
eofbit 연결된 입력 시퀀스가 파일 끝에 도달함

반환값

(없음)

예제

#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

참고 항목

상태 플래그를 반환합니다
(public member function)
상태 플래그를 수정합니다
(public member function)