1) ios::out | ios::ate will empty the file (so the second set of writes start at the beginning.
2) You can use:
3) Also, you are trying to write out more data that is in the file. You can use something like:Code:ofstream out2("file.dat", ios::out | ios::in | ios::binary | ios::ate);
Code:while (in.read((char*)&x, sizeof(int))) { cout << x; }




Reply With Quote