Unicode下
CString转TCHAR
TCHAR* szMsg = new TCHAR[wcslen(strAdbCmd)];
szMsg = strAdbCmd.GetBuffer(strAdbCmd.GetLength());
strAdbCmd.ReleaseBuffer();
用完了别忘了delete []szMsg;
CString转 char*
char * charP;
CString strP;
WideCharToMultiByte(CP_OEMCP,0,(LPCTSTR)strP,-1,charP,260,0,false);
char* TCHAR*转 CString
char cstr[20]=”sdaww”;
TCHAR tcstr[20]=_T(”unicode”);
CString str=CString(cstr);
CString str1=CString(tcstr);
CString转 int
CString strNum=_T(“”);
int value = _ttoi(static_cast<LPCTSTR>(strNum));
或者
int value = _ttoi(strNum);
int 转CString
int ia=1232;
CString stri= stri.Format(_T(“%d”),ia);
多字节字符集下
Cstring转化为char
转化成数组:
Cstring str=”convert”;
char char_str [512];
strncpy_s(char_str,(LPCTSTR)str_sum,sizeof(char_str));
转化成char指针:
char * ch_a =(char*)str.GetBuffer(str.GetLength());
char转化为Cstring
Cstring str;
char szBuff[2048];
str.Format("%s",szBuff);
CString 转 int :
n=atoi(str);