writing BINARY data to WIDE char streams

Hi there,

I have noticed that writing BINARY to WIDE character streams does not work as I expected.

Can anyone answer a simple question here:
stackoverflow.com/questions/38440613/writing-the-binary-file-using-wfstream


Please note that writing binary to char streams does work as we expect. However for wide chars there seems to be some kind of "check" and not all binary data are accepted. This is strange since unlike textual (i.e. formatted) output I do not expect any kind of "check" and/or translation for binary output.

thank you
Last edited on
Quark wrote:
I do not expect any kind of "check" and/or translation

Why do you not expect a translation? That's what wide streams do, they translate between Unicode (or other wide encoding, if one existed) code points, represented by wchar_t, on the program side and UTF-8/GB18030/other narrow multibyte encoding's code units (represented by chars) on the filesystem side. That's literally their only purpose.
Your ios::binary (seen in the code snippet on SO) comes into play later on, it controls whether those chars (code units) undergo additional transformations such as the endline translation.
Last edited on
you should not write a binary file using wide chars, just write it as bytes (which happen to be thin chars, but that is just by chance).
Topic archived. No new replies allowed.