1) ios::out | ios::ate will empty the file (so the second set of writes start at the beginning.

2) You can use:
Code:
ofstream out2("file.dat", ios::out | ios::in | ios::binary | ios::ate);
3) Also, you are trying to write out more data that is in the file. You can use something like:

Code:
while (in.read((char*)&x, sizeof(int)))
{
  cout << x;
}