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

24 lines
528 B
C++
Raw Permalink Normal View History

2022-12-20 17:31:11 +08:00
// textin2.cpp -- using cin.get(char)
#include <iostream>
int main()
{
using namespace std;
char ch;
int count = 0;
cout << "Enter characters; enter # to quit:\n";
cin.get(ch); // use the cin.get(ch) function
while (ch != '#')
{
cout << ch;
++count;
cin.get(ch); // use it again
}
cout << endl << count << " characters read\n";
// get rid of rest of line
// while (cin.get() != '\n')
// ;
//cin.get();
return 0;
}