Sorry if this is wasting your time, but I have no idea how to exactly use the .eof() in a while loop. I'm getting really frustrated not being able to find the right way. Help if you can or want, thanks you so very much in advance!
Sorry if this is wasting your time, but I have no idea how to exactly use the .eof() in a while loop. I'm getting really frustrated not being able to find the right way. Help if you can or want, thanks you so very much in advance!
Use it to test if you've reached EOF. Do NOT, however, use it as a loop condition unless you know what you're doing.
k, thanks
Don't use it at all. It is better to loop until the read fails.
Using eof at all has problems (other than to check to see if you attempted to read past the end of the file, which is mostly useless). It's possible for the read to succeed and eof to still be set, which would mean you fail to process your last piece of data. It's possible for a read to fail and the eof() to not be set, in which case you could process a piece of data twice or go into an infinite loop.Code:while (read data into your variable) { use variable here }
what about .good()
good() is better than eof() and is the same as checking the return value of the read operation, but it is harder to use. If you put the read into the while control, then you handle everything right there and the loop ends as soon as the read fails. If you check good(), then you have to do the read, then use an if statement with good() to see if you need to break out of the loop. It is not as clean.