1)其它数据类型转换为字符串: int i=100; long l = 2001; char temp[200]; 短整型(int) itoa(i,temp,10);///将i转换为字符串放入temp中,最后一个数字表示十进制 itoa(i,temp,2); ///按二进制方式转换 长整型(long) ltoa(l,temp,10);2)字符串转换为其它数据类型: strcpy(temp,"123"); //char temp[200]; 短整型(int) i = atoi(temp); 长整型(long) l = atol(temp); 浮点(double) d = atof(temp);
int nData = 1000; // 你要转换的值
char szBuffer[100];// 转换结果
int nResult;ltoa(nData, szBuffer,2); // szBuffer中得到的是二进制的值
nResult = strtol(szBuffer,NULL,2); //又转换回来了
ltoa(nData, szBuffer,10); // szBuffer中得到的是十进制的值
nResult = strtol(szBuffer,NULL,10); //又转换回来了
ltoa(nData, szBuffer,16); // szBuffer中得到的是十六进制的值
nResult = strtol(szBuffer,NULL,16); //又转换回来了可以根据你的需要任意组合 祝好运 ^_^
int i=100;
long l = 2001;
char temp[200];
短整型(int)
itoa(i,temp,10);///将i转换为字符串放入temp中,最后一个数字表示十进制
itoa(i,temp,2); ///按二进制方式转换
长整型(long)
ltoa(l,temp,10);2)字符串转换为其它数据类型:
strcpy(temp,"123"); //char temp[200];
短整型(int)
i = atoi(temp);
长整型(long)
l = atol(temp);
浮点(double)
d = atof(temp);