I'm writing a program where ifstream reads some characters from file, and skips some. However, when EOF is reached, it still tries to read, creating an infinite loop.
I have this type of code:
Using .eof() as a loop condition is almost always wrong. If read or seekg fails for some reason the failbit and/or badbit state will be set. It will cause all future read operations to fail so the end of the file is never reached and eofbit is never set, which is probably why your loop never stop.