I'm trying to use fstreams to read and write binary data to a file with the following code:
#include <fstream>
#include <iostream>
using namespace std;
int main(){
ofstream out("test.data", ios::binary);
for(uint i=0; i<10; i++){
uint outcount = i+100;
out.write((char*)&outcount, sizeof(uint));
}
ifstream in("test.data", ios::binary);
for(int i=0; i<10; i++){
uint incount;
in.read((char*)&incount, sizeof(uint));
cout << i << " " << incount << endl;
}
out.close();
in.close();
}
However it isn't working for me; it just keeps outputting "10" instead of 100, 101, etc. as I would expect.
What's my mistake?