Eärendil Baggins Eärendil Baggins - 3 years ago 225
C Question

How do I print Unicode to the output console in C with Visual Studio?

As the question says, do I have to do in order to print Unicode characters to the output console? And what settings do I have to use? Right now I have this code:

wchar_t* text = L"the 来";
wprintf(L"Text is %s.\n", text);
return EXIT_SUCCESS;


and it prints:
Text is the ?.


I've tried to change the output console's font to MS Mincho, Lucida Console and a bunch of others but they still don't display the japanese character.

So, what do I have to do?

Answer Source

This is code that works for me (VS2017) - project with Unicode enabled

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

int main()
{
    _setmode(_fileno(stdout), _O_U16TEXT);
    wchar_t * test = L"the 来. Testing unicode -- English -- Ελληνικά -- Español." ;

    wprintf(L"%s\n", test);
}

This is console

output

After copying it to the Notepad++ I see the proper string

the 来. Testing unicode -- English -- Ελληνικά -- Español.

OS - Windows 7 English, Console font - Lucida Console

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download