1,char*转换CString
char * pFileName = sItemValue;
int charLen = strlen(pFileName);
int len = MultiByteToWideChar(CP_UTF8,0,pFileName,charLen,NULL,0);
TCHAR *buf = new TCHAR[len + 1];
MultiByteToWideChar(CP_UTF8,0,pFileName,charLen,buf,len);
buf[len] = '/0'; //添加字符串结尾,注意不是len+1
//将TCHAR数组转换为CString
CString pWideChar;
pWideChar = buf;
delete []buf;
2,Unicode下CString转换为char *
CString str = _T("D://校内项目//QQ.bmp");
//注意:以下n和len的值大小不同,n是按字符计算的,len是按字节计算的
int n = str.GetLength(); // n = 14, len = 18
//获取宽字节字符的大小,大小是按字节计算的
int len = WideCharToMultiByte(CP_ACP,0,str,str.GetLength(),NULL,0,NULL,NULL);
//为多字节字符数组申请空间,数组大小为按字节计算的宽字节字节大小
char * pFileName = new char[len+1]; //以字节为单位
//宽字节编码转换成多字节编码
WideCharToMultiByte(CP_ACP,0,str,str.GetLength(),pFileName,len,NULL,NULL);
pFileName[len+1] = '/0'; //多字节字符以'/0'结束
3,连接char*
char* str1=strSTR;
const char* str2=sLanguageName;
char* str3=strXML;
int ilen = strlen(str1)+strlen(str2)+strlen(str3)+1;
char* str4 = new char[ilen];
strcpy(str4,str1);
strcat(str4,str2);
strcat(str4,str3);