参考链接
Unicode下CString和char *之间的互相转换-CSDN博客
(2)方法二:使用WideCh
#include <iostream>
using namespace std;
#include <atlstr.h>
int main()
{
CString str = L"liuxijiao计算机网络";
int n = str.GetLength(); //获取str的字符数
int len = WideCharToMultiByte(CP_ACP, 0, str, n, NULL, 0, NULL, NULL); //获取宽字节字符的大小,大小是按字节计算的
char *pChar = new char[len + 1]; //以字节为单位
WideCharToMultiByte(CP_ACP, 0, str, n, pChar, len, NULL, NULL); //宽字节编码转换成多字节编码
//=========================================================
// 特别提醒,这里不是len+1,而是len。结束符号不是 '/0',而是 '\0'
//=========================================================
pChar[len] = '\0'; //多字节字符以'\0'结束
cout<<pChar<<endl;
delete[] pChar;
return 0;
}