atoi 和 atof (把数字字符串转化为数字储存)

int atoi(char *s)
如果字符串内容是整数就返回该整数,否则返回0
double atof(char *s)
同上,不过返回浮点型

#include<iostream>
#include<cstdlib>
using namespace std;
int main(){
    char ch1[10] = "123456";
    int a = atoi(ch1);
    cout<<a<<endl;
    char ch2[10] = "123.456";
    a = atoi(ch2);
    double b = atof(ch2); 
    cout<<a<<endl<<b<<endl;
    char ch3[10] = "abc12";
    a = atoi(ch3);
    cout<<a;
    return 0;
} 

输出结果:

123456
123
123.456
0

posted @ 2017-12-25 22:49  WenOI  阅读(379)  评论(0编辑  收藏  举报
水波背景