textin3.cpp 431 B

1234567891011121314151617
  1. // textin3.cpp -- reading chars to end of file
  2. #include <iostream>
  3. int main()
  4. {
  5. using namespace std;
  6. char ch;
  7. int count = 0;
  8. cin.get(ch); // attempt to read a char
  9. while (cin.fail() == false) // test for EOF
  10. {
  11. cout << ch; // echo character
  12. ++count;
  13. cin.get(ch); // attempt to read another char
  14. }
  15. cout << endl << count << " characters read\n";
  16. return 0;
  17. }