textin4.cpp 374 B

12345678910111213141516
  1. // textin4.cpp -- reading chars with cin.get()
  2. #include <iostream>
  3. int main(void)
  4. {
  5. using namespace std;
  6. int ch; // should be int, not char
  7. int count = 0;
  8. while ((ch = cin.get()) != EOF) // test for end-of-file
  9. {
  10. cout.put(char(ch));
  11. ++count;
  12. }
  13. cout << endl << count << " characters read\n";
  14. return 0;
  15. }