What are you talking about exactly? If you write an int to the file, read an int to the file and use sizeof(int). If you write a short to the file then read a short to the file and use sizeof(short). If you have an int (and int is 4 bytes on your system) then writing 2 bytes of the integer isn't always going to work. Different machines with different endianness store the bytes in different orders. For example, if you have a 4-byte int that's set to 255, it might look in memory like 0x00FF0000 or 0x000000FF or probably even different combinations. Anyway, unless you really know what you're doing, write the entire variable to the file and read the entire variable back from the file. And also note that if you try to read the int in from the file it might not be the right number if the file was created on a different computer.