将字符串变成浮点数或整型的函数

来源:互联网 发布:河南淘宝运营招聘 编辑:程序博客网 时间:2024/05/16 06:43

http://www.cplusplus.com/reference/clibrary/cstdlib/atof/

double atof(const char *nptr)函数可以将一个字符串变成浮点数。

#include<iostream>

using namespace std;

int main()

{

double f;

char*str=”123.456”;

f=atof(str);

cout<<f<<endl;

}

 

具体看上面链接.

把字符串变成整型的函数为

int atoi ( const char * str );
用法与atof类似;
参考http://www.cplusplus.com/reference/clibrary/cstdlib/atoi/