c++字符函数库 cctype

来源:互联网 发布:assert java 编辑:程序博客网 时间:2024/05/29 13:38
// 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");   }

0 0
原创粉丝点击