EdwardShare

导航

 

//第一种方式:
CString str = _T("CSDN");
USES_CONVERSION;
std::string s(W2A(str));
//第二种方式:
CString str = _T("CSDN");
std::string s = (CT2A)str;

string转Cstring

CString str;
std::string s=“CSDN“;
str=s.c_str();

3.CString转const char*

//第一种方式:(CString转char*转const char*)
CString str=_T("CSDN");
const char* cstr;
char temp[100];
::wsprintfA(temp, "%ls",(LPCTSTR)str);
cstr = temp;
//第二种方式:(CString 转string转const char*)
CString str = _T("CSDN");
USES_CONVERSION;
std::string s(W2A(str));
const char* cstr = s.c_str();

 

4. const char*转CString

const char* cstr = "CSDN";
CString str(cstr);
posted on 2022-12-22 14:54  程序员的夏天  阅读(2018)  评论(0编辑  收藏  举报