VC常用数据类型使用转换详解

一、其它数据类型转换为字符串


短整型(int)
itoa(i,temp,10);///将i转换为字符串放入temp中,最后一个数字表示十进制
itoa(i,temp,2); ///按二进制方式转换 
长整型(long)
ltoa(l,temp,10);

 

三、字符串转换为其它数据类型
strcpy(temp,"123"); 

短整型(int)
i = atoi(temp); 
长整型(long)
l = atol(temp); 
浮点(double)
d = atof(temp);

四、其它数据类型转换到CString
使用CString的成员函数Format来转换,例如:


整数(int)
str.Format("%d",i); 
浮点数(float)
str.Format("%f",i); 
字符串指针(char *)等已经被CString构造函数支持的数据类型可以直接赋值
str = username;

posted @ 2013-09-04 15:36  狂师  阅读(278)  评论(0编辑  收藏  举报