#include <iostream>
int main ()
{
using namespace std;
char ch;
int count = 0; Use basic input
cout << "Enter characters; Enter # to quit:\n ';
CIN >> ch; Get a character while
(ch!= ' # ') //test the character
{
cout << ch; echo the character
++count; Count the character
cin >> ch; Get the next character
}
cout << Endl << count << "characters read\n";
return 0;
}
The above code loop completes the character input
Here is one of the output results:
Enter characters; Enter # to quit:
Ken Run#really Fast
Seekenrun
9 characters Read
Analysis: Why the program output ignored the space.
Explanation: The reason is in CIN. Spaces and line breaks are ignored when CIN reads. Therefore, the spaces in the input are not echoing, and the count is not included.
Additional input to CIN will be cached, and input will not be sent to the program unless the ENTER key is pressed.