64,637
社区成员
发帖
与我相关
我的任务
分享
setlocale(LC_ALL,"chs");
const char *str="中国";
wchar_t wcs[10];
mbstate_t mbt={0};
const char *p=str;
mbsrtowcs(wcs,&p,strlen(str)+1,&mbt);
for(wchar_t *p=wcs;*p!=0;p++)
printf("%X\n",(unsigned short)*p);
wchar_t* AnsiToUnicode(const char* buf)
{
int len = ::MultiByteToWideChar(CP_ACP, 0, buf, -1, NULL, 0);
if (len == 0) return L"";
wchar_t* wch=new wchar_t[len];
memset(wch,0,len);
::MultiByteToWideChar(CP_ACP, 0, buf, -1, wch, len);
return wch;
}
#include <iostream>
using namespace std;
int main()
{
wchar_t wstr[] = L"中国";
cout << showbase << hex;//指定输出格式:showbase显示0x,hex十六进制显示
for(int i = 0; wstr[i]; ++i)
cout << (unsigned short)wstr[i] << endl;
return 0;
}