CString及string,char *与其他数据类型的转换和操作

(2)转换:
●数学类型与CString相互转化
数学类型转化为CString
可用Format函数,举例:
CString s;
int i = 64;
s.Format("%d", i)
CString转换为数学类型:举例
CString strValue("1.234");
double dblValue;
dblValue = atof((LPCTSTR)strValue);
●CString与char*相互转换举例
CString strValue(“Hello”);
char *szValue;
szValue=strValue.GetBuffer(szValue);
也可用(LPSTR)(LPCTSTR)对CString//  进行强制转换. 
szValue=(LPSTR)(LPCTSTR)strValue;
反过来可直接赋值:
char *szChar=NULL;
CString strValue;
szChar=new char[10];
memset(szChar,0,10);
strcpy(szChar,”Hello”);
strValue=szChar;
Tags: 

延伸阅读

最新评论

发表评论