I have a code
#include <iostream>
#include <sstream>
using namespace std;
int main() {
stringstream ss("123 ab 4");
int a, b, c;
ss >> a;
ss >> b;
ss >> c;
cout << "XXX_ " << a << ' ' << b << ' ' << c << endl; // XXX_ 123 0 796488289
}
Why variable b
is 0? Is there a rule of handling invalid type in stringstream (e.g. value is “ab” but type is int)?