std::string CStringToSTDStr(const CString& theCStr)
{
// Convert the CString to a regular char array
const int theCStrLen = theCStr.GetLength();
char *buffer = (char*)malloc(sizeof(char)*(theCStrLen+1));
memset((void*)buffer, 0, sizeof(buffer));
WideCharToMultiByte(CP_UTF8, 0, static_cast<cstring>(theCStr).GetBuffer(), theCStrLen, buffer, sizeof(char)*(theCStrLen+1), NULL, NULL);
// Construct a std::string with the char array, free the memory used by the char array, and
// return the std::string object.
std::string STDStr(buffer);
free((void*)buffer);
return STDStr;
}
将MFC的CString 类型转化为C++标准数据类型std::string
最新推荐文章于 2022-04-07 20:25:41 发布