c++ stream 상태
2023. 8. 28. 15:36ㆍc,c++/c++ 관련 개념 및 문법
std:: ios 입출력 클래스
비트 플래그
goodbit
eofbit
failbit
badbit
메서드
good()
eof()
fail()
bad()
로 상태를 나타낸다
cin에서 알아볼 수 있다.
#include <iostream>
#include <string>
using namespace std;
void printStates(const std::ios& stream)
{
cout << std::boolalpha; // boolalpha option ON
cout << "Good() = " << stream.good() << '\n'; // 모든 error state flag가 0일 때 flag가 true가 된다.
cout << "eof() = " << stream.eof() << '\n'; // stream의 end of file에 도달하면 flag가 true가 된다.
cout << "fail() = " << stream.fail() << '\n'; // error state flag가 하나라도 1일 경우 flag가 true가 된다.
cout << "bad() = " << stream.bad() << '\n'; // 데이터를 읽거나 쓸 때 에러가 발생할 때 flag가 true가 된다.
}
int main()
{
while(true)
{
int i;
cin >> i;
printStates(cin);
cin.clear();
cin.ignore(1024, '\n');
cout << endl;
}
return 0;
}
입력 버리기
cin.ignore(10, '\n'); // 100개의 문자를 버리는데 그 전에 new line 문자를 버리면 바로 멈춘다
cin.ignore(LLONG_MAX, '\n'); //최대 문자 수를 버린다.
'c,c++ > c++ 관련 개념 및 문법' 카테고리의 다른 글
inline 함수 (0) | 2023.08.24 |
---|---|
c++ string class 구현 (0) | 2023.08.22 |
C++ 문자열 parsing (0) | 2023.08.22 |
복사 생성자와 소멸자 (0) | 2023.07.15 |
explicit 키워드, mutable 키워드 (0) | 2023.07.11 |