If I have:
double x;
cin >> x;
then I proceed to enter a character or a string, what would happen? And what would the statement cin >> x return?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The
istream::operator>>always returns anistreamobject, no matter what. The value ofxhowever would be undefined, and theistreamwould be “errored” and wouldn’t work again till you cleared the error state.This is just from memory and I really haven’t thought about this before, so if someone sees that this is wrong, I’ll remove it.