C++ crash when use setmode with _O_U8TEXT to deal with unicode

Viewed 2103

What I've tried to print unicode is

_setmode(_fileno(stdout), _O_U8TEXT);
string str = u8"unicode 한글 hangul";
cout << str << endl;

I used setmode to show and get unicode correctly, but It crashed with Debug Assertion Fail.

However,

_setmode(_fileno(stdout), _O_U16TEXT);
wstring str = L"unicode 한글 hangul";
wcout << str << endl;

_O_U16TEXT compile and print correctly.

What should I do to use UTF-8? Do I have to find another trick?

1 Answers
Related