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

18 lines
448 B
C++
Raw Permalink Normal View History

2022-12-20 17:31:11 +08:00
// textin3.cpp -- reading chars to end of file
#include <iostream>
int main()
{
using namespace std;
char ch;
int count = 0;
cin.get(ch); // attempt to read a char
while (cin.fail() == false) // test for EOF
{
cout << ch; // echo character
++count;
cin.get(ch); // attempt to read another char
}
cout << endl << count << " characters read\n";
return 0;
}