I am new to c++ programming. I have read how parsing can be done in SO questions using vector(Int tokenizer).But I have tried the following for array. I am able to parse only one number from string. If input string is "11 22 33 etc".
#include<iostream>
#include<iterator>
#include<vector>
#include<sstream>
using namespace std;
int main()
{
int i=0;
string s;
cout<<"enter the string of numbers \n";
cin>>s;
stringstream ss(s);
int j;
int a[10];
while(ss>>j)
{
a[i]=j;
i++;
}
for(int k=0;k<10;k++)
{
cout<<"\t"<<a[k]<<endl;
}
}
If I give input as "11 22 33"
output
11
and some garbage values.
If i have initialized stringstream ss("11 22 33"); then its working fine. What am I doing wrong?