一、Cstring ---> double、int
在unicode字符集环境下:
CString str"abcd";
int a = _wtoi(str.GetBuffer());
double b = _wtof(str.GetBuffer());
在多字节环境下:
CString str"abcd";
int a = atoi(str.GetBuffer());
double b = atof(str.GetBuffer());
二、int、double--->CString
int i=123;
double d=123.0;
CString str;
str.format("%d",i);
str.format("%lf",d);
三、CString--->char*
CString str="abcd";
char *p=(LPSTR)(LPCTSTR)str;
四、CString与CStringA相互转换
CString cstring=_T("hello");
CStringA cstringa=_T("HELLO");
CString cstringTmp;
cstringTmp=cstringa;
CStringA cstringaTmp;
cstringaTmp=cstring;
//注意:需要使用上述的方法,即赋值运算符,直接采用拷贝构造会出错,例如这样赋值CStringA cstringaTmp=cstring;
五、Htuple、CString相互转化
HTuple Tup;
CString Cstr;
CStringA StrTemp(Cstr);
Tup = (LPSTR)STRTEMP.GetBuffer();
HTuple Tup;
CString Cstr;
Tup[0] = Cstr.GetBuffer();
HTuple Tup;
CString Cstr;
Cstr = Tup[0].S();
转载于:https://blog.51cto.com/green906/2070580