I'm looking at a program written in a professionally published book:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
#include <iostream>
using namespace std;
int main()
{
char ch;
int count = 0;
cout << "enter characters; enter # to quit:\n";
cin >> ch;
while (ch != '#')
{
cout << ch;
count++;
cin >> ch;
}
cout << endl << count << " characters read\n";
return 0;
}
|
My question is: If you put in the sample input (after being prompted to enter characters):
This is the song that never ends it goes on and on my friends
cin is reading that into a character, right? But a character can only hold 1 character at a time out of that input I just put in.
-- So where are the other characters going?
-- Are they being put into unallocated space in memory?
-- Or are they sitting in the input stream for processing INTO the program?
I guess I'm just failing to see
-- at what point does the input actually reach the program?
-- and why can I read a sentence into a char using cin?
-- Wouldn't it be more appropriate to use a string?
Sorry for all the questions; it just seems like an odd input machanism.