64,685
社区成员
发帖
与我相关
我的任务
分享
//#include "stdafx.h "
#include "tchar.h"
//#include <iostream.h>
#include <LOCALE.h>
#include <atlbase.h>
//using namespace std;
char* WSTRToAnsi(WCHAR* Msg)//把wchar*转换称char*
{
int len = wcstombs(NULL, Msg, 0);
char* buf = new char[len+1];
wcstombs(buf, Msg, len);
buf[len] = 0;
return buf;
}
int main()
{
WCHAR* d=L"速度";//此处如果是英文,可以成功,如果是汉字,则失败
// cout.imbue(locale("chs"));///这样写可以
setlocale(LC_ALL,"chs");///////////////////////本地化
char* s =WSTRToAnsi(d);
printf( "%s\n ",s);//?
return 0;
}