#include "afxwin.h"
#include <iostream>
using namespace std;
int main()
{
CString cs = _T("西游记");
AfxMessageBox(_T("CString:") + cs);
// CString 转 ACSII
CT2A a_str(cs);
string std_str(a_str);
cout << "CString 转 string:" << std_str << endl;
const char* pa_str = a_str;
cout << "CString 转 const char *:" << pa_str << endl;
// const char * 转 CString
const char* a_char = "孙悟空";
cout << endl << a_char << endl;
CString wuKong(a_char);
AfxMessageBox(_T("const char * 转 CString:") + wuKong);
// string 转 CString
string baJie = "猪八戒";
CString erShiXiong(baJie.c_str());
AfxMessageBox(_T("string 转 CString:") + erShiXiong);
// 用下面这种方式
const char* sanShiDi = "沙和尚";
CA2T sanShiDi_T(sanShiDi);
CString wuJing(sanShiDi_T);
AfxMessageBox(_T("const char * 转 CString:") + wuJing);
return 0;
}
标签:std,CT2A,CString,C++,CA2T,str,cs
From: https://www.cnblogs.com/huvjie/p/18021016