textin2.cpp 505 B

1234567891011121314151617181920212223
  1. // textin2.cpp -- using cin.get(char)
  2. #include <iostream>
  3. int main()
  4. {
  5. using namespace std;
  6. char ch;
  7. int count = 0;
  8. cout << "Enter characters; enter # to quit:\n";
  9. cin.get(ch); // use the cin.get(ch) function
  10. while (ch != '#')
  11. {
  12. cout << ch;
  13. ++count;
  14. cin.get(ch); // use it again
  15. }
  16. cout << endl << count << " characters read\n";
  17. // get rid of rest of line
  18. // while (cin.get() != '\n')
  19. // ;
  20. //cin.get();
  21. return 0;
  22. }