When you do this, the process first skips any whitespace, then continues to extract characters so long as they form a valid part of an integer.
1 2
int foo;
ss >> foo;
On the other hand, this will first skip any whitespace, them consider any subsequent characters as a valid part of a string until the next whitespace (or end of stream) is encountered.
1 2
string s;
ss >> s;
Still, the original question said each part was separated by a space. So you could have done something like this: ss << 100 << ' ' << 'f' << ' ' << "hello" << ' ' << 200;
OK thanks. Your right about the question anyway. But out of interest in my example why does it stop when it encounters the char f but does not stop when it encounters the int 200?
I tried to explain previously.
'f' is not part of a valid integer so extraction stops there.
'2' is a valid character which can be part of a string, so extraction does not stop.
That's right. A stringsteam behaves in many ways just like a disk file, or like an ordinary cin / cout. That's because they are all types of stream with similar characteristics.