write an array integer to file
Apr 13, 2009 at 7:31pm UTC
Hi everybody,
I want to write an array integer in a file. I have this piece of code
1 2 3 4 5
int var[7]={0,2,0,3,0,4,0};
int i;
ofstream outfile("test.txt" , ios::out);
outfile.write ((char *) &var, sizeof (var));
outfile.close();
in the file I see this:
00 00 00 00
02 00 00 00
00 00 00 00
03 00 00 00
00 00 00 00
04 00 00 00
00 00 00 00
I don't understand why it writes the numbers in the most significant byte. That is: instead of 02 00 00 00 I thought I should read this one 00 00 00 02
Do you know why does it work like this?
Thank you very much
RAdeberger
Apr 13, 2009 at 7:35pm UTC
You are running on a little endian machine, which means that in memory the LSB is stored in the lowest memory address.
Apr 15, 2009 at 8:16am UTC
Thank you very much!
Topic archived. No new replies allowed.