I have noticed that writing BINARY to WIDE character streams does not work as I expected.
Can anyone answer a simple question here:
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.
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.