I have the following code successfully compiled:
#include <io.h>
#include <fcntl.h>
#include <iostream>
#include <cstddef>
#include <cstdio>
int main()
{
_setmode(_fileno(stdout), _O_U16TEXT);
char16_t chinese[] = u"\u4e66\u4e2d\u81ea\u6709\u9ec4\u91d1\u5c4b";
wprintf(L"String written with unicode codes: %ls \n", chinese);
wchar_t arabic[] = L"أَبْجَدِيَّة عَرَبِيَّة";
wprintf(L"String written with L-String: %ls \n", arabic);
std::wcout << std::endl; std::system("PAUSE");
}
It prints:
- String written with unicode codes: 书中自有黄金屋
- String written with L-String: أَبْجَدِيَّة عَرَبِيَّة
However, the compiler issues a warning for chinese case (not for arabic case):
warning C4477: 'wprintf' : format string '%ls' requires an argument of type 'wchar_t *', but variadic argument 1 has type 'char16_t *'
What would be then the correct wprintf format string?