C++ cin count characters

Description

C++ cin count characters

#include <iostream>

int main()//from w w  w. java  2s . c o m
{
  long count {};
  char ch {};

  std::cout << "Please enter a sequence of characters terminated by '#':" << std::endl;

  do {
    std::cin >> ch;
    ++count;
  } while (ch != '#');

  // do not count '#' as a character
  --count;
  std::cout << "You entered characters (not counting spaces and the terminal #)." << std::endl;
}



PreviousNext

Related