c++之字符函数库cctype

c++从c语言继承来的函数库,这些库函数可以大大简化字符判断和转换的操作

#include <iostream>
#include <cctype>
using namespace std;
int main() 
{
    
    
	char ch;
	int letters = 0;
	int digits = 0;
	int whitespace = 0;
	int punctuations = 0;
	int others = 0;
	cin.get(ch);
	while (ch != '@')
	{
    
    
		if (isalpha(ch))
			letters++;
		else if (isdigit(ch))
			digits++;
		else if (isspace(ch))
			whitespace++;
		else if (ispunct(ch))
			punctuations++;
		else
			others++;
		cin.get(ch);
	}
	cout << letters << endl <<
		digits << endl <<
		whitespace << endl <<
		punctuations << endl <<
		others << endl;
	return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_45867397/article/details/107570707