std::string WString2String(const wchar_t* pwc )
{
if (!pwc || !pwc[0])
return "";
std::string result;
int nLen=WideCharToMultiByte( CP_ACP, 0, (LPCWSTR)pwc, -1, NULL, 0, NULL, NULL );
if(nLen<=0)
{
return std::string( "" );
}
char *presult=new char[nLen];
if ( NULL == presult )
{
return std::string("");
}
WideCharToMultiByte( CP_ACP, 0, (LPCWSTR)pwc, -1, presult, nLen, NULL, NULL );
presult[nLen-1]=0;
result = presult;
delete [] presult;
return result;
}
C++数据类型转换
于 2011-01-09 13:33:00 首次发布