我常用的几个:
其它数据类型转换为字符串
短整型(int)
itoa(i,temp,10);///将i转换为字符串放入temp中,最后一个数字表示十进制
itoa(i,temp,2); ///按二进制方式转换
长整型(long)
ltoa(l,temp,10);
字符串转换为其它数据类型
短整型(int)
i = atoi(temp);
长整型(long)
l = atol(temp);
浮点(double)
d = atof(temp);
字符串转化为char*
1.CString s;
char * p = (LPSTR)(LPCTSTR)s;
2.CString s;
char temp[100];
strcpy(temp, s);
3.Cstring theString("Test string");
char ptr=theString.GetBuffer(theString.GetLength());
其它数据类型转换到CString
使用CString的成员函数Format来转换,例如:
整数(int) str.Format("%d",i);
浮点数(float) str.Format("%f",i);
字符串指针(char *)等已经被CString构造函数支持的数据类型可以直接赋值
str = username;
char * p = (LPSTR)(LPCTSTR)s;
2.CString s;
char temp[100];
strcpy(temp, s);
3.Cstring theString("Test string");
char ptr=theString.GetBuffer(theString.GetLength());
其它数据类型转换到CString
使用CString的成员函数Format来转换,例如:
整数(int) str.Format("%d",i);
浮点数(float) str.Format("%f",i);
字符串指针(char *)等已经被CString构造函数支持的数据类型可以直接赋值
str = username;