vendredi 29 juillet 2016

Why does stringstream not move to next set of characters when cout?

string inputLine = "1 2 3";
stringstream stream(inputLine);

// Case One
int x, y, z;
stream >> x;
stream >> y;
stream >> z;
// x, y, z have values 1, 2, 3

// Case Two
cout << stream << endl;
cout << stream << endl;
cout << stream << endl;
// All 3 print out 1

For the above code, why is it when you assign to an int, stringstream moves to the next set of characters, but not with cout?

Aucun commentaire:

Enregistrer un commentaire