Take from: cppreference
Until C++11:
If extraction fails (e.g. if a letter was entered where a digit is expected), value is left unmodified and failbit is set.
Since C++11:
If extraction fails, zero is written to value and failbit is set. If extraction results in the value too large or too small to fit in value,
std::numeric_limits<T>::max()
orstd::numeric_limits<T>::min()
is written and failbit flag is set.
Due to this change, this means that the following snippet:
int x = 1;
std::cin >> x;
return x;
in the event that the numerical conversion fails, will return 1
before C++11, and 0
otherwise.
Why would the standard committee introduce such a subtle breaking change? Or rather, what kind of code was possible prior to C++11 that warranted this change?