Why is failbit set when eof is found on read?

The failbit is designed to allow the stream to report that some operation failed to complete successfully. This includes errors such as failing to open the file, trying to read data that doesn’t exist, and trying to read data of the wrong type. The particular case you’re asking about is reprinted here: char buffer[10]; stream.read(buffer, … Read more

fgetc, checking EOF

You can’t cast the return value to char because the return value could be EOF, and EOF value is system-dependent and is unequal to any valid character code. link Usually it is -1 but you should not assume that. Check this great answer from the c-faq-site: Two failure modes are possible if, as in the … Read more

How to read user input until EOF?

In Python 3 you can iterate over the lines of standard input, the loop will stop when EOF is reached: from sys import stdin for line in stdin: print(line, end=”) line includes the trailing \n character Run this example online: https://ideone.com/rUXCIe This might be what most people are looking for, however if you want to … Read more

Representing EOF in C code?

EOF is not a character (in most modern operating systems). It is simply a condition that applies to a file stream when the end of the stream is reached. The confusion arises because a user may signal EOF for console input by typing a special character (e.g Control-D in Unix, Linux, et al), but this … Read more