c++ 数字字符串互转

c++ stdlib.h内有原生的函数:数字字符串互转

//字符串转数字
int i = atoi("66");
printf("%d",i);
double f =atof("2013.14");
printf("%lf",f);

//数字转字符串
char str[64];
itoa(666,str,10);
printf(str);//666
gcvt(3.1415926,10,str);//第二个参数为转字符串长度不包含小数点
printf(str);//3.1415926
 

实现

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章