I am storing some data in a sting & I'm retriving it using stringstream but the problem is that it repeates last element two times.I could not understand why is this happning?Is there anyone who can help me on solving this problem?
Programme code is as follows:::::::::::::
#include<iostream>
#include<sstream>
using namespace std;
int main()
{
int i,x;
stringstream sstr;
string line;
for(i=0;i<3;i++) {
getline(cin,line);
sstr<<line;
while(sstr) {
sstr>>x;
cout<<x<<" "; //output repeates last element two times
}
cout<<endl;
sstr.clear();
}
return 0;
}