Doesn't C++ offer any guarantee about keeping variables intact on input failure? With older versions of gcc, a program like this one keeps the -1 value of i on failure (for instance if a letter is typed instead of a number on input). With Ubuntu 10.10 (gcc 4.4.5), i is reset to zero in case of input failure.
#include <iostream>
int main()
{
int i = -1;
std::cin >> i;
std::cout << "i = " << i << '\n';
return 0;
}
This behavior breaks a lot of my code. I suppose the gcc people know what they are doing, and it is likely to be my mistake. If anyone knows the standard, I'd like to know what it says about this situation.
Thanks.