码迷,mamicode.com
首页 > 其他好文 > 详细

转换MFC CString 到std::string

时间:2014-06-08 16:33:53      阅读:218      评论:0      收藏:0      [点我收藏+]

标签:cstring   string   

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

转换MFC CString 到std::string

标签:cstring   string   

原文地址:http://blog.csdn.net/qsw1214/article/details/28612425

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!