Outputting unicode characters to the windows console is a bit of a mess. In theory, we should be able to use wprintf or wcout. In reality, these seem to be unreliable at best and probably totally broken. Fortunately, the native windows functions seem to work fine.
Here is a sample program. It requires MSVC.NET and the source must be saved as unicode. Dev-C++ will not compile unicode source files, so for that compiler, some alterations must be made.
Code:
#include <windows.h>
#include <stdio.h>
#include <iostream>
#include <strsafe.h>
using namespace std;
/*
* Version of wprintf that uses windows functions
*/
DWORD win_wprintf(LPCWSTR szFormat, ...)
{
# ifndef ARRAY_SIZE
# define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
# endif
WCHAR szText[1024 * 10];
va_list args;
DWORD dwWritten;
/* Format the text into the buffer */
va_start(args, szFormat);
StringCchVPrintfW(szText, ARRAY_SIZE(szText), szFormat, args);
va_end(args);
/* Output the buffer to the console. */
if (WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), szText, lstrlenW(szText), &dwWritten, NULL))
{
return dwWritten;
}
return 0;
}
int main(void)
{
printf("Before continuing make sure the console font is set to 'Lucida Console'\n");
getchar();
/* Try with the C std library. */
wprintf(L"ęŃźŚłŁĘĄĆŻżĶaz09!> %s\n", L"Ććķ");
/* Try with the C++ std library. */
wcout << L"ęŃźŚłŁĘĄĆŻżĶaz09!> " << L"Ććķ" << endl;
/* Try with the windows replacement. */
win_wprintf(L"ęŃźŚłŁĘĄĆŻżĶaz09!> %s\n", L"Ććķ");
getchar();
}
In my testing, wprintf and wcout output nothing while win_wprintf gives the correct result.