// 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++字符函数库 cctype
最新推荐文章于 2024-09-14 07:15:00 发布
本文介绍了一个简单的C++程序,该程序能够统计用户输入文本中的字母、数字、空白字符及标点符号的数量,并输出统计结果。
377

被折叠的 条评论
为什么被折叠?



