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

版权声明:欢迎转载并请注明出处,谢谢~~ https://blog.csdn.net/chimomo/article/details/7713405
/*
 * Created by Chimomo
 */

#include<iostream>
#include<math.h>

using namespace std;

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

int main() {
    long t = 0;
    long l = convertStrToLong("123456", t);
    cout << l << endl;
    return 0;
}

// Output:
/*
123456

*/

猜你喜欢

转载自blog.csdn.net/chimomo/article/details/7713405
今日推荐