1、使用W2A函数,使用该函数需要加载USES_CONVERSION,具体用法如下:
bool GMotionData::LoadPosData()
{
USES_CONVERSION;
string myStrName ;
CString strName;
myStrName = W2A(strName);
return true;
}
2、使用CT2A
Ctring myStr = _T("hahha");
string AlgorithmType = CT2A(myStr.GetBuffer());
string 转CString
1、自定义函数
CString AUTOCSD_API change00(string str)
{
size_t size/* = str.length()*/;
size = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, str.c_str(), -1, NULL, 0);
wchar_t *buffer = new wchar_t[size + 1];
MultiByteToWideChar(CP_ACP, 0, str.c_str(), -1, buffer, size * sizeof(wchar_t));
buffer[size] = 0;
CString strRet(buffer);
delete[] buffer;
return strRet;
}
2.使用c_str()
参考: