0
点赞
收藏
分享

微信扫一扫

atoi() 函数实战

小桥流水2016 2022-03-14 阅读 77
知识图谱
//
int atoi( const char* s ); 

01 头文件
    #include<cstdlib>  // std not str !!!
02 返回值
    return 字符串 起始部分 最长的 int 值, 若起始部分就为非数字 return 0

// eg.
#include<bits/stdc++.h>
using namespace std;

const int N=111;
char str[N];

int main()
{
    while( ~scanf("%s",str) )
    {
        printf("%d\n",atoi(str) );
    }
    return 0;
}
// 可能的输出:
// 123.456
// 123
// 123www
// 123
// 0.1
// 0
// www111       // 注意 开头就不是数字的话 return 0
// 0

举报

相关推荐

0 条评论