I am trying to write a UTF-16 encoded file using std::ofstream(). Even in binary mode writing "\n\0"
is written as "\r\n\0"
. Sample code:
std::string filename = ...
std::ofstream fout(filename, std::ios_base::binary);
fout.write("\xff\xfe", 2);
fout.write("\n\0", 2);
fout.close();
The resulting file's hex data is:
ff fe 0d 0a 00
I must be doing something wrong. Any ideas to prevent the 0x0d being written?
I am using MS VisualStudio 2013.
Update: It inexplicably started working as expected. Chalk it up to ghosts in the machine.