直接用系统自带的Stoi函数搞定
stoi函数会做范围检查,所需转换的数字如果超出int范围,即超出[-2147483648,2147483648],会出现Runtime Error!!!
#include <bits/stdc++.h>
using namespace std;
int conversNum(string s) {
return stoi(s, 0, 16);
}
int main() {
string s;
getline(cin,s);
cout<<conversNum(s);
return 0;
}