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; }</cstring>
转换MFC CString 到std::string,布布扣,bubuko.com
原文地址:http://blog.csdn.net/qsw1214/article/details/28612425