C++ (Visual Studio 2015/windows)의 이진 파일에서 부울을 읽는 데 문제가 있습니다. 부울을 읽으려고하기 전에 istream은 좋지만 읽은 후에 failbit가 설정되고 스트림은 eof가 아니고 badbit도 설정되지 않습니다.C++ 바이너리 파일 및 failbit에서 부울 읽기
오류 비트에 대한 몇 가지 문서 상태 : "bad()와 같은 경우에 true를 반환하지만 정수를 읽으려고 할 때 알파벳 문자가 추출 될 때처럼 형식 오류가 발생하는 경우에도 마찬가지입니다. 번호."
기본적으로 스트림이 좋고 끝나지 않은 경우 이진 스트림에서 부울을 읽는 것이 실패 할 수 있음을 기본적으로 이해하지 못합니다. 내 가정은 부울로 읽을 수있는 비트가 하나뿐이므로 형식이 없습니다. 아마도 failbit이 설정된 다른 조건이 있습니까?
void Parser::binary2Record(std::istream& in) {
bool is_next_booking;
in >> current_record_;
in >> is_next_booking;
Segment segment;
while (!is_next_booking && in) {
in >> segment;
current_record_.addSegment(segment);
std::cout << "State of io before reading boolean " << (in.good() ? "Good" : "Not good") << std::endl;
in >> is_next_booking;
std::cout << "State of io good after reading boolean " << (in.good() ? "Good" : "Not good") << std::endl;
std::cout << "State of io fail after reading boolean " << (in.fail() ? "fail" : "Not fail") << std::endl;
std::cout << "State of io bad after reading boolean " << (in.bad() ? "Bad" : "Not Bad") << std::endl;
std::cout << "State of io eof after reading boolean " << (in.eof() ? "Eof" : "Not eof") << std::endl;
}
}
Output:
State of io before reading boolean Good
State of io good after reading boolean Not good
State of io fail after reading boolean fail
State of io bad after reading boolean Not Bad
State of io eof after reading boolean Not eof
정말 있습니까? 너는 eof 또는 무엇이든을 검사하고 있지 않다. – SingerOfTheFall
형식이 지정된 텍스트 추출을 사용하여 이진 데이터를 읽을 수 없습니다. –