Writing utf16 to file in binary mode

前端 未结 6 1133
逝去的感伤
逝去的感伤 2020-11-27 04:44

I\'m trying to write a wstring to file with ofstream in binary mode, but I think I\'m doing something wrong. This is what I\'ve tried:

ofstream outFile(\"tes         


        
6条回答
  •  青春惊慌失措
    2020-11-27 05:26

    On windows using wofstream and the utf16 facet defined above fails becuase the wofstream converts all bytes with the value 0A to 2 bytes 0D 0A, this is irrespective of how you pass the 0A byte in, '\x0A', L'\x0A', L'\x000A', '\n', L'\n' and std::endl all give the same result. On windows you have to open the file with an ofstream (not a wofsteam) in binary mode and write the output just like it is done in the original post.

提交回复
热议问题