1

While trying to write some wide characters to a file, all output to the file stops after those characters. I don't know what's going on.

wofstream file("c:\\test.txt");

file << L"seen" << L"您好" << "unseen";
ST3
  • 8,826
  • 3
  • 68
  • 92
Bluebaron
  • 2,289
  • 2
  • 27
  • 37

1 Answers1

1

Non-ASCII characters in source code are parsed in an implementation defined way. Use either hex sequences or the newer (post-c99 or C++11) unicode character literals and use their UTF-8/16/32 codepoint representations.

This is implementation defined behavior, so unless you are absolutely sure you compiler does what you expect, don't do this.

rubenvb
  • 74,642
  • 33
  • 187
  • 332
  • My compiler and ide both allow this and do it properly – Bluebaron Oct 26 '11 at 17:56
  • This is just an example. The actual data is coming from the registry on a Chinese employee's workstation. – Bluebaron Oct 26 '11 at 17:57
  • Bluebaron: http://codepad.org/m2bTCgxN. Do the characters fit in a 2-byte `wchar_t`? Windows doesn't support anything that does not fit in a 2-byte `wchar_t`, unfortunately... – rubenvb Oct 26 '11 at 18:27