C++ 解决万恶的输入字符串分割成正整数的问题
vector<int> numSplit(string s) {
vector<int> num;
//利用istringstream读取字符串的特性分割之间有空格的正整数序列!
istringstream str(s);
string out;
while (str >> out) {
int temp = 0;
for (int i = 0; i <out.size(); i++) {
//一个简单的进十位操作
temp = temp * 10;
temp += out[i] - '0';
}
//将数字存在我们需要的整数数组输出
num.emplace_back(temp);
}
return num;
}
头文件:#include<sstream>
只适合消除空格,其他字符需要再思考一下