- 论坛徽章:
- 0
|
本人编写国际化时碰到了一个问题,以下代码在gb环境时输出没问题,但utf-8却正常无法输出,十分苦恼!!!请指教。
#include <stdio.h>
#include <locale.h>
#include <wchar.h>
int main()
{
size_t len;
char * locp;
char *src="中华人民共和国a";
size_t nbytes;
wchar_t dst[100];
mbstate_t state;
memset (&state, '\0', sizeof (state));
len = strlen(src);
printf("mbs len is %d\n",len);
//locp = setlocale(LC_ALL, "zh_CN.gbk");
//locp = setlocale(LC_ALL, "zh_CN.gb2312");
locp = setlocale(LC_ALL, "zh_CN.UTF-8");
printf("You have set Locale to %s\n",locp);
mbsrtowcs(dst,&src,len,&state);
printf("%d\n", wcslen(dst));
printf("%ls\n",dst);
//wprintf("%ls\n",dst);
return 0;
} |
|