Link to home
Create AccountLog in
Avatar of Unimatrix_001
Unimatrix_001Flag for United Kingdom of Great Britain and Northern Ireland

asked on

Reading more than possible from a file.

What happens in the following:

fileInput.read(memoryBlock, 512);
fileInput.close();

But from the current read position to the end of the file is only 511 bytes? Will it read 511 bytes and silently ignore the 512 byte, or should a specific check be done to ensure 512 bytes are there, and handle accordingly?

Thanks,
Uni
ASKER CERTIFIED SOLUTION
Avatar of Infinity08
Infinity08
Flag of Belgium image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of AlexNek
AlexNek

Lets imagine that 512 is only buffer size so the buffer can containt 512 or less symbols.
Avatar of Unimatrix_001

ASKER

Infinity: Thanks very much! As a side question, what is the point in having both an eofbit and a failbit if one also sets the other?

Alex: Perhaps you forgot to put an answer with that?

Uni.
>> what is the point in having both an eofbit and a failbit if one also sets the other?

when the eofbit is set - it doesn't necessarily mean that the failbit is set too - in this specific case it's true though :

    eofbit is set because the end of the file is reached
    failbit is set because you tried to read further than the end of the file

There's a slight difference in meaning ...
Ah I understand now. :)