原型:

int atoi(const char *nptr);
 
头文件:#include <stdlib.h>
 

简介

atoi(ascii to integer):是把字符串转换成整型数的一个函数。atoi( ) 函数会扫描参数 nptr字符串,跳过前面的空白字符(例如空格,tab缩进等。——百度百科

 

栗子:

    #include<iostream>
    #include<stdio.h>
    #include<cstdlib>
    using namespace std;

    int main()
    {
        char s[101];
        int n;
        scanf("%s",s);
        n=atoi(s);
        printf("%d\n",n);

        getchar();//吸收回车
        gets(s);//输入带有空格的字符串会在空格处终止
        n=atoi(s);
        printf("%d\n",n);
        return 0;
    }

 



相关文章:

  • 2021-05-20
  • 2021-12-11
  • 2022-12-23
  • 2021-05-06
  • 2022-12-23
猜你喜欢
  • 2021-06-17
  • 2022-12-23
  • 2021-08-27
  • 2022-12-23
  • 2022-01-12
  • 2021-07-30
  • 2020-03-31
相关资源
相似解决方案