c++字符函数库 cctype

// isalpha()  检查是否为字母字符;
// isdigit()  测试字符是否为数字字符 ;
// isspace()   测试字符是否为空白,如换行符、空格和制表符;
// ispunct()    测试字符是否为标点符号;



#include <iostream>
#include <cctype>
using namespace std;

int main()
{
     cout <<"enter txet:\n";
     char ch;
     int chars=0;
     int whitespace=0;
     int digits=0;
     int punct =0;
     int outher=0;
    
     cin.get (ch);
     while (ch!='@')
     {
           if (isalpha(ch))
           chars++;
           else if(isspace(ch))
           whitespace ++;
           else if (isdigit(ch))
           digits ++;
           else if (ispunct(ch))
           punct ++;
           else
           outher++;
           cin.get (ch);          
          
           }
           cout << chars<<" letters, ";
           cout <<whitespace<<" whitespae, ";
           cout <<digits<<" digits, ";
           cout <<punct <<" punctuations, ";
           cout <<outher <<" outhers. \n";
                   
   
   
    system("PAUSE");
   
}

你可能感兴趣的:(C++)