這是一個ANSI C問題。我有以下代碼。wchar_t vs wint_t
#include <stdio.h>
#include <locale.h>
#include <wchar.h>
int main()
{
if (!setlocale(LC_CTYPE, "")) {
printf("Can't set the specified locale! "
"Check LANG, LC_CTYPE, LC_ALL.\n");
return -1;
}
wint_t c;
while((c=getwc(stdin))!=WEOF)
{
printf("%lc",c);
}
return 0;
}
我需要完整的UTF-8支持,但即使在這個最簡單的級別,我能否以某種方式改進它?爲什麼使用wint_t
,而不是wchar
,並做了適當的更改?
好的,謝謝。所以,簡而言之:什麼時候使用wchar_t更好?爲什麼不總是使用wint_t? – 2009-07-04 19:42:40
`wint_t`是``wchar_t`什麼`int`是`char`。儘管`getc()`返回`int`能夠返回'EOF`,我們不會爲窄字符串使用'int'數組。同樣,即使`getwc()`返回`wint_t`能夠返回`WEOF`,我們也不會爲寬字符串使用`wint_t`數組。 – musiphil 2012-05-23 07:29:13
@musiphil:你的評論應該是一個答案,它是唯一一個談論它們之間的概念*差異的人。 – MestreLion 2015-03-05 19:38:52