int i,j;
std::string s;
std::cin>>i>>j>>s>>s>>i;
std::cout<<i<<" "<<j<<" "<<s<<" "<<i;
Question
Referring to the sample code above, what’s the displayed output if the input string given is: “5 10 Sample Word 15 20”?
The answer is
15 10 Word 15
I have the question is what’s the underline policy for cin to over write the existing values? Does the latter one simply overwrite the previous one? Is there any other situations?
I checked many books, but I didn’t find one which explain this.
is equivalent to:
Every time you read from cin to a variable, the old contents of that variable is overwritten.
So you are explicitly asking to overwrite
sandi.