宽字节 中文乱码 留底!

作者在 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;
}


c语言 | 阅读 1294 次
文章评论,共1条
lxy789
2018-07-26 21:55
1
666
游客请输入验证码
浏览1294次
文章归档
最新评论