int i; float a;
i = (int) a; // float 到 int
a = (float) i; // int 到 float
-------------------------------------
与char 的互换 用 C 语言的读(sscanf)写(sprintf) [C语言是C++的一部分],看下面的例子:
#include <stdio.h>
void main()
{
int i=123;
float a=234.5;
char s1[10],s2[10];
char s3[]="987", s4[]="876.5";
sprintf(s1,"%d",i); // int to char
sprintf(s2,"%f",a); // float to char
printf("%s %s/n",s1,s2);
sscanf(s3,"%d",&i); // char to int
sscanf(s4,"%f",&a); // char to float
printf("%d %f",i,a);
}
http://blog.csdn.net/liquanhai/article/details/4462309
一周热门 更多>