Printing Unicode strings in Windows console

Posted on May 12, 2014

Win32 Console Applications do not display Unicode strings properly. There is a simple solution of using _setmode(). You need to include two headers.

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

int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
	_setmode(_fileno(stdout), _O_U16TEXT);

	wcout << L"안녕하세요?" << endl;
	// or
	// wprintf(L"%s\n", L"안녕하세요?");

	return 0;
}