转换MFC CString 到std::string

来源:互联网 发布:淘宝店铺增加粉丝数量 编辑:程序博客网 时间:2024/05/11 07:48
std::string CStringToSTDStr(const CString& theCStr){// Convert the CString to a regular char arrayconst 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>


1 0
原创粉丝点击