Just a quick one.( I'm using a library computer so I don't have access to a compiler)
If I were to prompt for a value from the standard input stream (keyboard) and use the statement;
int num1,num2;
cin%26gt;%26gt;num1%26gt;%26gt;num2;
And when I run the .exe and get the following output:
"Please enter two numbers:"
To which I type in the following:
24 25
Which is 3 spaces, the number 24, 3 spaces, the number 25 and 2 spaces. Will the variables num1 and num2 receive the vals 24 and 25 as expected? So spaces play a part in this
input or is C++ smart enough to pick out the numbers from the stream I provide from the keyboard?
C++ question about imput using cin?
cin ignores whitespace, so any thing like a space or return character regardless of the number of them are ignored. So yes, num1 would be 24 and num2 would be 25.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment