您的位置:首页 > 编程语言 > C语言/C++

C++ - 编写一个从字符串转变成长整型的函数

2012-07-03 22:25 453 查看
#include<iostream>
#include<math.h>

#define NULL 0

using namespace std;

long convert(char*string,long integer)
{
for(int sLen=strlen(string),i=0;i<sLen;integer+=(long)(string[i++]-'0')*pow(10.0,sLen-i-1));
return integer;
}

void main()
{
long tmp=0;
long l=convert("123456",tmp);
cout<<l<<endl;
}

// Output:
/*
123456
*/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐