c++ 输入
输入为:
1 2 3 4 5,6
输出为:
1 2 3 4 5
6
#include <iostream>
#include <sstream>
#include <vector>
using namespace std;
int main()
{
vector<int> res;
string s, s1;
getline(cin,s);
char spl = ',';
vector<string> strings;
istringstream iss(s);
string token;
// while(iss >> s1)
// {
// cout << s1 << endl;
// }
while(getline(iss, token, spl))
{
strings.push_back(token);
}
istringstream iss2(strings[0]);
string token2;
while(iss2 >> token2)
{
res.push_back(atoi(token2.c_str()));
}
for(auto x: res)
{
printf("%d ", x);
}
puts("");
printf("%d", atoi(strings[1].c_str()));
return 0;
}
while
输入
while(~scanf("%d%d", &n, &m))
原理链接while(cin >> n >> m)