首页 > 代码库 > CString 转换为 wchar_t *

CString 转换为 wchar_t *

1、将CString转换为const char*  

CString str = _T("231222");

std::string strDp = CStringA(str);  //或: std::string strDp = CT2A(str, CP_ACP);

2、将const char*转换为wchar_t*类型

size_t len = strDp.length() + 1;
size_t converted = 0;
wchar_t * WStr = (wchar_t*)malloc(len * sizeof(wchar_t));
mbstowcs_s(&converted, WStr, len, strDp.c_str(), _TRUNCATE);

CString 转换为 wchar_t *