Windows下mbcs和unicode编码的转换.

1. 从MBCS转到UNICODE

方法a) 直接调用windows api

    char name[100] ="大鳄.hxboar";
    
    wchar_t wname[100];

    //setlocale(LC_ALL, "chinese"); 
    int nLen = MultiByteToWideChar(CP_ACP, 0,name, -1, NULL, NULL);
    MultiByteToWideChar(CP_ACP, 0, 
       name, -1, wname, nLen);
View Code

方法b)用swprintf

 wchar_t buf[100];
         setlocale(LC_ALL, "chs");
         swprintf(buf, 100, L"%S", "世界你好");
         wprintf(L"%s\n", buf);
View Code

 

Powered by Jekyll and Theme by solid

本站总访问量