(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;
本文介绍了CString与其他数据类型之间的转换方法,包括数学类型与CString的互相转换,以及CString与char*之间的转换示例。通过具体实例展示了如何使用Format函数及atof等函数实现不同类型间的转换。
792

被折叠的 条评论
为什么被折叠?



