I took the following example literally from Walter Savitch Absolute C++ book. It works (as one would expect from a scholar such as Walter Savitch). However, I am puzzled why as I will explain after the code citation:
cout << "Enter a line of input and I will echo it:\n";
char symbol;
do
{
cin.get(symbol);
cout << symbol;
} while (symbol != '\n');
cout << "That's all for this demonstration.\n";
Possible output will look as follows:
Enter a line of input and I will echo it:
Do Be Do 1 2 34
Do Be Do 1 2 34
That's all for this demonstration.
My problem is the following. In going through the loop just once, cin.get(symbol) will find one character at a time, and cout will then output this one character consequently. Then, if my input wasn't a '\n' character, it will go into the loop for the second time, and so on, until finally the input equals '\n'.
However, in executing the code, all the input seems to be read at once, and then copied back at once. How can this happen if every input character needs to be checked to be equal to '\n'?
Final point, probably stating the obvious: this question does not pertain to code that is some way not syntactical. I am just puzzled about what happens during compilation and/or execution of the simple code I present above.
Hopefully someone can help me out!
Thanks.