PracticeDev/study_cpp/cpp_primer_source_code/Chapter 5/textin1.cpp

23 lines
637 B
C++
Raw Normal View History

2022-12-20 17:31:11 +08:00
// textin1.cpp -- reading chars with a while loop
#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";
// get rid of rest of line
// while (cin.get() != '\n')
// ;
//cin.get();
return 0;
}