sfile will not enter the error state until a read operation has failed. That means that when all the data has been read, the loop while(sfile) runs one more time. sfile.read((char*)&s,sizeof(s)); fails, leaving s unchanged, so the same data is printed twice. To fix this you should put the read operation as the loop condition.