Note that there are some explanatory texts on larger screens.

plurals
  1. POOutput unicode strings in Windows console app
    primarykey
    data
    text
    <p>Hi I was trying to output unicode string to a console with <em>iostreams</em> and failed.</p> <p>I found this: <a href="https://stackoverflow.com/questions/1922294/using-unicode-font-in-c-console-app">Using unicode font in c++ console app</a> and this snippet works.</p> <pre><code>SetConsoleOutputCP(CP_UTF8); wchar_t s[] = L"èéøÞǽлљΣæča"; int bufferSize = WideCharToMultiByte(CP_UTF8, 0, s, -1, NULL, 0, NULL, NULL); char* m = new char[bufferSize]; WideCharToMultiByte(CP_UTF8, 0, s, -1, m, bufferSize, NULL, NULL); wprintf(L"%S", m); </code></pre> <p>However, I did not find any way to output unicode correctly with iostreams. Any suggestions?</p> <p>This does not work:</p> <pre><code>SetConsoleOutputCP(CP_UTF8); utf8_locale = locale(old_locale,new boost::program_options::detail::utf8_codecvt_facet()); wcout.imbue(utf8_locale); wcout &lt;&lt; L"¡Hola!" &lt;&lt; endl; </code></pre> <p><strong>EDIT</strong> I could not find any other solution than to wrap this snippet around in a stream. Hope, somebody has better ideas.</p> <pre><code>//Unicode output for a Windows console ostream &amp;operator-(ostream &amp;stream, const wchar_t *s) { int bufSize = WideCharToMultiByte(CP_UTF8, 0, s, -1, NULL, 0, NULL, NULL); char *buf = new char[bufSize]; WideCharToMultiByte(CP_UTF8, 0, s, -1, buf, bufSize, NULL, NULL); wprintf(L"%S", buf); delete[] buf; return stream; } ostream &amp;operator-(ostream &amp;stream, const wstring &amp;s) { stream - s.c_str(); return stream; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload