您的位置:首页 > 其它

将unicode下的wstring转化成ansi下的string

2011-03-11 16:36 447 查看
//将unicode下的wstring转化成ansi下的string
inline std::string UnicodeToASCII(LPCTSTR lpszText)
{
int length=_tcslen(lpszText);
TCHAR* pWideCharStr=new TCHAR[length+1];
char* data=new char[2*length+2];
_tcscpy(pWideCharStr, lpszText);
WideCharToMultiByte(CP_ACP, 0, pWideCharStr, -1, data, 2*length + 2, NULL, NULL);
std::string strText = data;
delete []data;
delete []pWideCharStr;
return strText;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: