函数: int atoi(const char *str);
 函数: long atol(const char *str);
    1.  扫描 str 字符串, 跳过str前面的空格(注意只能是跳过Tab 空格 换行 回车键;若为其他就会停止  转换);
    2.  从第一个数字字符(或是-、+)开始转换,终止于第一个非字符. 
  函数
:double atof(const char *str);
  str 以 E 或 e 除外的其他非数字字符结尾, 其他同atoi(char *str); 
函数:char  _itoa(int Val, char* str, int radix); 
   注意: itoa()或者_itoa()都不是标准库函数,并不是所有的编译器都能编译通过.
  Val: 要转化的数值;
  str: 转化后,存放的字符数组;
  radix: 转化的进制 2~36;
附加:
  sprintf(char *str, "%d",...); 比itoa()功能更强大.且为标准库<stdio.h>所有.
  sprintf(char *str, "%o",...);
  sprintf(char *str, "%x",...);

给上程序测试案例:

 

  1. #include<cstdlib>  
  2. #include<cstdio>  
  3. #include<cstring>  
  4. int main()  
  5. {  
  6.     /*以下是atoi(), atof(), atol()的调用*/ 
  7.     char *a = new char[20];  
  8.      strcpy(a,"0102"); //a = 0102  
  9.      a[0] = 13;       //或者 a[0] = 10; a[0] = 32;   
  10.     int i = atoi(a);  
  11.     //cout<<"Test_atoi: i = "<<i<<endl;  
  12.     printf("Test_atoi:i = %d\n",i);//i = 102; 忽略了换行    
  13.     a = "  12.01E3";  
  14.     double f = atof(a);  
  15.     //cout<<"Test_atof: f = "<<f<<endl; //f=12010  
  16.     printf("Test_atof:f = %.2lf\n",f);  
  17.                                                  /*****************/ 
  18.     /*itoa(int,char*,int radix) 在stdlib.h中声明,但不是标准库函数*/ 
  19.     int Val = 1234567;                          /*****************/ 
  20.     char *p = new char[20];  
  21.     _itoa(Val,p,10); // itoa(Val,p,10);  
  22.     //cout<<"Test_itoa: p = "<<p<<endl;  
  23.     char *tmp1 = new char[50];  
  24.     strcpy(tmp1,"Test_itoa: p = ");  
  25.     strcat(tmp1,p);  
  26.     puts(tmp1);  
  27.       
  28.     /*用sprintf();代替itoa()的功能; sprintf()在stdio.h中声明*/ 
  29.     char *s = new char[50];  
  30.     int val = 2345678;  
  31.     sprintf(s,"%d",val);  
  32.     //cout<<"Test_Sprintf: s = "<<s<<endl;  
  33.     char *tmp2 = new char[50];  
  34.     strcpy(tmp2,"Test_Sprintf: s = ");  
  35.     strcat(tmp2,s);  
  36.     puts(tmp2);  
  37.       
  38.     system("pause");  
  39.     return 0;  
  40. }