textin1.cpp 615 B

12345678910111213141516171819202122
  1. // textin1.cpp -- reading chars with a while loop
  2. #include <iostream>
  3. int main()
  4. {
  5. using namespace std;
  6. char ch;
  7. int count = 0; // use basic input
  8. cout << "Enter characters; enter # to quit:\n";
  9. cin >> ch; // get a character
  10. while (ch != '#') // test the character
  11. {
  12. cout << ch; // echo the character
  13. ++count; // count the character
  14. cin >> ch; // get the next character
  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. }