EOF on binary files

Jul 2, 2011 at 2:02pm
As far as I know, binary files doesn't exactly have an EOF, right? How can I find the end of a binary file?
Jul 2, 2011 at 3:02pm
They do have EOF, actually. It's why the .get() function on streams returns an integer and not a character, so you can compare it to the EOF constant.
Jul 2, 2011 at 3:05pm
I actually coded this:

1
2
3
4
5
FicheroEntrada.seekg(0, ios::end);
size=(int) FicheroEntrada.tellg();
FicheroEntrada.seekg(0,ios::beg);
while(FicheroEntrada.tellg()<size){
.........


It does works, although I don't know what bugs/errors can come from this.
Jul 2, 2011 at 9:48pm
Should work fine.
Jul 2, 2011 at 11:58pm
http://www.cplusplus.com/reference/iostream/istream/read/
If the End-of-File is reached before n characters have been read, the array will contain all the elements read until it, and the failbit and eofbit will be set (which can be checked with members fail and eof respectively).

¿How are you reading the file?

@LB: dunno how the filesystem establish that you reached the end, but I don't think that it uses a special character. If that was the case, ¿how will you distinguish between EOF and data?
Jul 2, 2011 at 11:59pm
It's why the .get() function on streams returns an integer and not a character, so you can compare it to the EOF constant.


*cough*not a character value*cough*
Jul 3, 2011 at 12:18am
You shouldn't smoke.
You perform a get(), and have as result EOF. That does not meant that the file has stored EOF.
Jul 3, 2011 at 12:20am
I never said that the EOF was in the file, just that they do have an EOF flag given by the OS.
Topic archived. No new replies allowed.