作者在 2018-07-25 10:50:12 发布以下内容
#include <stdio.h>
#include <locale.h>
//编译连接加上 -fexec-charset=GB2312 -finput-charset=GB2312 //GBK
wchar_t * ANSIToUnicode( const char* str )
{
int textlen ;
wchar_t * result;
textlen = MultiByteToWideChar( CP_ACP, 0, str,-1, NULL,0 );
result = (wchar_t *)malloc((textlen+1)*sizeof(wchar_t));
memset(result,0,(textlen+1)*sizeof(wchar_t));
MultiByteToWideChar(CP_ACP, 0,str,-1,(LPWSTR)result,textlen );
return result;
}
int main(int argc, char *argv[])
{
setlocale(LC_ALL,"");
char* str="中国";
//wchar_t* wstr=ANSIToUnicode("中国");
wchar_t* wstr=L"中国";
printf("1:%s\n", str);
wprintf(L"2:%ls\n", wstr);
return 0;
}