Prev article
Newer
Next article
Older
Two methods to write Unicode text to the console are:
Note: After you call _setmode(_O_U16TEXT), any calls to printf() (non-wide) will fail with an assertion.
_setmode(_O_U16TEXT)
printf()
#include "stdafx.h" #include <io.h> // for _setmode #include <fcntl.h> // for _O_U16TEXT #include <windows.h> // for WriteConsoleW int main() { // Copyright symbol, pound symbol, Unicode code point U+03A3 Greek Capital Letter Signma Σ wchar_t wide[] = L"\r\nCopyright © £ \u03a3"; // method 1 _setmode(_fileno(stdout), _O_U16TEXT); wprintf(wide); // method 2 auto handle = GetStdHandle(STD_OUTPUT_HANDLE); WriteConsoleW(handle, wide, wcslen(wide), NULL, NULL); return 0; }
Program output:
Ads by Google
© Richard McGrath