My code is just like this:
UPDATED
#include <iostream> #include <fstream> using namespace std; int main(int argc, char **argv) { ifstream r("foo.bin", ios::binary); ofstream w("foo.bin", ios::binary); int i; int ints[10] = {0,1,2,3,4,5,6,8,9}; w.write((char*)&ints, sizeof(ints)); int in_ints[10]; r.read((char*)&in_ints, sizeof(in_ints)); for(i = 0;i < 10;i++) { cout << in_ints[i] << " "; } cout << endl; return 0; }
Now part of the recording looks successful, for example, executing the od command with 32-bit lengths (my system is 32 bits) will display the correct sequence, including a hexadecimal dump.
However, I get random sequences of such and negative integers that should not happen (they are separated and basically zeros, since my integers are small, the signed bits should not be included.)
You see why my reading method did not work when it really is the opposite of my writing method?
John S.
source share