I am using sstream to parse a string. The string contains an arbitrary number of integers separated by spaces. But sstream is not parsing the input properly. Here's my code-
#include<cstdio>
#include<cstring>
#include<vector>
#include<cstdlib>
#include<sstream>
#include<iostream>
using namespace std;
vector<int> val[10010];
int main(){
int n,i,j,temp;
stringstream stream;
string s;
scanf("%d",&n);
vector<int>::iterator it;
for(i=0; i<n; i++){
getline(cin,s);
stream.str(s);
while(1) {
stream >> temp;
val[i].push_back(temp);
if(!stream)
break;
}
for(it=val[i].begin(); it!=val[i].end(); it++)
printf("%d ",*it);
printf("\n");
}
return 0;
}
Here are the test cases : Code