first of all, open the file with std::ios::binary, second get the file size from a call to seekg(0,std::ios::end) and tellg() third, use the file size that you got instead of the eof() call to tell you got to the end. That is all. Goodbye.