多字节模式下:
CString -->char *
1 CString str1 ="123";
2 char *t1 =str1.GetBuffer(str1.GetLength());
3 str1.ReleaseBuffer();
View Code
char * -->CString
1 char *str ="aaaa"
2
3 CString str1(str);
CString -->int
1 CString str1 ="123";
2 int i =atoi(str1);
int -->CString
1 int i =100;
2 CString str;
3 str.Format("%d",i);
Unicode编码模式下
CString -->char *
1 CString str1 =_T("123");
2 int len =WideCharToMultiByte(CP_ACP,0,str1,-1,NULL,0,NULL,NULL);
3 char *ptxtTemp =new char[len +1];
4 WideCharToMultiByte(CP_ACP,0,str1,-1,ptxtTemp,len,NULL,NULL );
5
6 //...
7 delete[] ptxtTemp;
char * -->CString
1 char *p ="test";
2 CString str(p);
3 //...
CString -->int
CString str2 =_T("100");
int i;
swscanf(str2,_T("%d"),&i);
View Code
int -->CString
1 int j =100;
2 CString str3;
3 str3.Format(_T("%d"),j);