r/learncpp • • Aug 23 '21
endianness
When writing numbers to files using ofstream, on my little endian machine those numbers are written in little endian, but I assume that for big endian machines those numbers are written in big endian, I want to be certain ofstream doesn't handle endianness for me. Also how do you suggest I safely write to files?
4
Upvotes
View all comments
Show parent comment
1
u/HappyFruitTree Aug 23 '21 edited Aug 23 '21
It's because char is one byte. If you write a string of wchar_t you would run into the same issue with endianess as with unit16_t, not because it's a string but because wchar_t consists of multiple bytes.