+ 1

Why does cin, expecting an int, change the corresponding int variable to zero in case of invalid input ?

Moreover , when I give input a and Enter it takes 0 for first integer and -1098876708 code : int a,b; cout<<"enter "<<endl; cin>>a>>b; cout<<a<<" "<<b;

1st Nov 2017, 4:01 AM
Akashdeep Nandi
Akashdeep Nandi - avatar
2 odpowiedzi
+ 5
What is your input?
1st Nov 2017, 4:50 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 1
If input "a" is 5 and input "b" is hello the output will be 5 0. Remember that in SoloLearn you must enter multiple inputs on separate lines. #include<iostream> using namespace std; int main () { int a, b; cout << "Enter (a) and (b) " << endl; // If user inputs // 5 && hello cin >> a >> b; // The output will be // 5 0 cout << a << " " << b << endl; return 0; }
1st Nov 2017, 5:02 PM
Bob
Bob - avatar