write an array integer to file

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
You are running on a little endian machine, which means that in memory the LSB is stored in the lowest memory address.

Thank you very much!
Topic archived. No new replies allowed.