0
파일을 이진 모드로 열면 is_open()
은 true
이지만 good()
은 false
입니까?개방시 스트림이 좋지 않습니까?
bool ok = false;
std::ifstream stream("test.dat", std::ios::binary)
if (stream.is_open())
{
ok = stream.good();//Does a situation exist where the result of this is false ?
stream.close();
}
파일이 비어 있다면'good()'은 false를 반환 할 수 있지만 보장되지는 않습니다. 첫 번째 읽기 시도까지. – Praetorian
아니요. 그러나 is_open() 호출 이후의 모든 I/O 작업은 bad, fail 또는 eof 비트를 설정할 수 있습니다. – imreal
@ Prætorian 파일이 비어 있으면 eof 비트가 설정되어 I/O 작업이 수행되지 않습니다. – imreal