using stringstream to read individual words from a sentence vs using it to parse comma separated integers behaves differently than how I expected it to.
string ok = "hello how is it going";
stringstream ss(ok);
string tmp;
while(ss)
{
ss >> tmp;
cout << tmp << endl;
}
i'd expect the output to be-
hello
how
is
it
going
but the output is-
hello
how
is
it
going
going
what confuses me is if I use it differently-
string ok = "10,11,12";
stringstream ss(ok);
int n;
char ch;
while(ss)
{
ss >> n >> ch;
cout << n << endl;
}
i get the desired output which is-
10
11
12
and not 12 being repeated as in the case with strings