This seems odd:
int main(int argc, char* argv[]) { cout << "function main() .." << '\n'; char ch = 0; double number_value=1.1; cin >> ch; cin.putback(ch); cin >> number_value; cout << "1 .. " << " " << cin.good() << " " << number_value << '\n'; cin >> number_value; cout << "2 .. " << " " << cin.good() << " " << number_value << '\n'; return 0; }
If I enter the following:
7a 1
I get the following:
function main () ..
7a 1 1 .. 1 7 2 .. 0 0
I understand:
1 .. 1 7
but why the variable number_value is 0. cin.good() shows a failure, so it would not read anything, and the value in number_value from the previous destination would remain. I expect a value of 7.
source share