数字字符串转整型函数

数字字符串转整型



#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>

using namespace std;
 
int main() 
{
    string a = "12345###123";
    char c = '1';
    if(isdigit(c)) cout << "yes\n"; // 判断字符是否为 0 - 9 (即数字)
    
    //下面三个都是转到第一个非数字的字符 头文件为string 或者cstring
    cout << stoi(a) << '\n'; // 转为int型 直到第一个非数字字符 下面同上
    cout << stol(a) << '\n'; // 转为long型
    cout << stoll(a) << '\n'; // 转为long long型
    
  
    return 0;
}
posted @ 2021-03-29 21:19  ccz9729  阅读(169)  评论(2编辑  收藏  举报