why are you checking the eof before any read operation occurred? eof flag is set by read operation when EOF is encountered. After just opening file it will be false even if the file is empty.