| Prashant Gupta PG (134) | |||
why is this function reading the last object of file twice
| |||
|
|
|||
| EssGeEich (1007) | |||
Because f.eof() is true if the file ALREADY reached the end of file. You should loop on f.read().
| |||
|
|
|||
| Prashant Gupta PG (134) | |
| Ok thank for the help.But why it is so that f.eof() is true if the file ALREADY reached the end of file.And when does eof() exactly returns false?? | |
|
|
|
| EssGeEich (1007) | |
|
It returns false when it didn't reach the end of file. Let me give you an example: We have a 4-byte example file. We will read 2-byte "packets". 1. Read and Store Data. read returns a nonzero value. 2/4 bytes read. 2. eof() returns false. eof flag isn't set. 3. Read and Store Data. read returns a nonzero value. 4/4 bytes read. 4. eof() returns false. eof flag isn't set. 5. Read and Store Data. read returns a zero value. Cannot go over 4/4, eof flag set. 6. eof() returns true as the eof flag is set. | |
|
|
|
| Prashant Gupta PG (134) | |
| awesome, I want to give a thumb up to this explanation. | |
|
|
|