代码:
#include <stdio.h>
#include <wchar.h>
#define USE_W
int main()
{
#ifdef USE_W
const wchar_t *ae_utf16 = L"\x00E6 & ASCII text ae\n";
wprintf(ae_utf16);
#else
const char *ae_utf8 = "\xC3\xA6 & ASCII text ae\n";
printf(ae_utf8);
#endif
return 0;
}
输出:
ae & ASCII 文本 ae
虽然 printf 产生正确的 UTF-8 输出:
æ & ASCII 文本 ae
你可以在这里测试一下。