How to display and enter data like wchar_t[]?


The question is how to do it on Windows. On Linux it's easy

setlocale(LC_CTYPE, "");
//а потом wprintf ...

On Windows, this does not work. Would like it to be something like this.

#ifdef __linux__ 
  setlocale(LC_CTYPE, "");
#elif defined _WIN32

Needed to output Cyrillic, hieroglyphs, etc. We need exactly wchar_t .

PS MinGW gcc -dumpversion 4.8.1

PPS Answer 1 works on MS Visual C++ 2010 (without stdafx.h)


You need to call _setmode(_fileno(stdout), _O_U16TEXT);

#include <iostream>
#include <io.h>
#include <fcntl.h>

int wmain(int argc, wchar_t* argv[])
    _setmode(_fileno(stdout), _O_U16TEXT);

    std::wcout << L"Testing unicode -- English -- Ελληνικά -- Español." << std::endl;
    // или
    wprintf(L"Testing unicode -- English -- Ελληνικά -- Español.\n");

    return 0;

Support for specific characters depends on the console font. Lucida Console and Consolas handle everything except hieroglyphs.

Solution taken from en-SO answer – Output unicode strings in Windows console app

Scroll to Top