C++ ofstream binary output of max int

-1

Currently I'm trying to write the maximum int value into a file. Unfortunately the result is not what I expect:

std::ofstream File;    
File.open(fileName, std::ios::out | std::ios::binary);

char* data = NULL;
unsigned int tempNumberInt = 0xFFFFFFFF;
data = reinterpret_cast<char*>(&tempNumberInt);
File.write(data,sizeof(tempNumberInt));

File.close();

Nevertheless, when I check the result in the hexeditor

c2 a4 c2 a4 c2 a4 c2 a4

is written instead of

ff ff ff ff

So, not only the value is not what I expected but also the 8 bytes are exported instead of 4. What am I doing wrong?

c++
binary
ofstream
asked on Stack Overflow Mar 13, 2019 by Flo

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0