File truncates after hitting a wide character

2019-08-02 17:14发布

问题:

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";

回答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.



标签: c++ wofstream