2
代碼:爲什麼wprintf將Unicode連字分隔成兩個不同的字形?
#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
您可以測試這個here。
感謝您使用wprintf之前有關設置語言環境的要求的信息。 – user206334 2013-04-08 10:40:04
這適用於Linux。在Windows上,嘗試將區域設置爲UTF-8代碼頁[將失敗](https://msdn.microsoft.com/zh-cn/library/x99tb11d.aspx)。 AFAICT,'wprintf'不能用來在那裏打印一個UTF-8字符串。 [WriteConsole](https://msdn.microsoft.com/en-us/library/windows/desktop/ms687401(v = vs.85).aspx)是必需的。 – mgiuffrida 2016-12-03 05:24:14