std::basic_ios<CharT,Traits>:: operator!
|
bool
operator
!
(
)
const
;
|
||
연관된 스트림에서 오류가 발생한 경우
true
를 반환합니다. 구체적으로,
true
를 반환하는 조건은
badbit
또는
failbit
가
rdstate
(
)
에 설정된 경우입니다.
목차 |
매개변수
(없음)
반환값
true 오류가 발생한 경우, false 그 외의 경우.
예제
#include <cstdlib> #include <fstream> #include <iostream> int main() { std::ifstream file("test.txt"); if (!file) // operator! is used here { std::cout << "File opening failed\n"; return EXIT_FAILURE; } // typical C++ I/O loop uses the return value of the I/O function // as the loop controlling condition, operator bool() is used here for (int n; file >> n;) std::cout << n << ' '; std::cout << '\n'; if (file.bad()) std::cout << "I/O error while reading\n"; else if (file.eof()) std::cout << "End of file reached successfully\n"; else if (file.fail()) std::cout << "Non-integer data encountered\n"; }
참고 항목
다음 표는 가능한 모든 basic_ios 접근자( good() , fail() 등)의 값과 ios_base::iostate 플래그 조합 간의 관계를 보여줍니다:
| ios_base::iostate 플래그 |
basic_ios
접근자
|
|||||||
eofbit
|
failbit
|
badbit
|
good() | fail() | bad() | eof() | operator bool | operator! |
| false | false | false | true | false | false | false | true | false |
| 거짓 | 거짓 | 참 | 거짓 | 참 | 참 | 거짓 | 거짓 | 참 |
| 거짓 | 참 | 거짓 | 거짓 | 참 | 거짓 | 거짓 | 거짓 | 참 |
| 거짓 | 참 | 참 | 거짓 | 참 | 참 | 거짓 | 거짓 | 참 |
| 참 | 거짓 | 거짓 | 거짓 | 거짓 | 거짓 | 참 | 참 | 거짓 |
| 참 | 거짓 | 참 | 거짓 | 참 | 참 | 참 | 거짓 | 참 |
| 참 | 참 | 거짓 | 거짓 | 참 | 거짓 | 참 | 거짓 | 참 |
| 참 | 참 | 참 | 거짓 | 참 | 참 | 참 | 거짓 | 참 |