12.C++:strtol() 字符串转长整型函数

版权声明:本博客为记录本人学习过程而开,内容大多从网上学习与整理所得,若侵权请告知! https://blog.csdn.net/Fly_as_tadpole/article/details/82873644

字符串转长整型函数

long int strtol(const char *nptr,char **endptr,int base);

这个是函数原型,nptr就是我们的字符串endptr是结束符(NULL就是\0),base是进制数,默认的0(10进制)

#include <iostream>
#include <stdlib>
int main(int argc, char const *argv[])
{
    printf("the num is : %d", strtol(argv[1], NULL, 0));
    return 0;
}

最后就可以把传入的数字字符串,转换为整形了!

猜你喜欢

转载自blog.csdn.net/Fly_as_tadpole/article/details/82873644