C++Primer Plus第六章分支语句和逻辑运算符练习1 cctype类的使用,函数isdigit(),islower(),isupper(),toupper(),tolower()函数的使用

在这里插入图片描述


#pragma region 练习1.cpp

#if 1
#include <iostream>
#include<cctype>
int main()
{
	using namespace std;
	char temp;
	cout << "请开始你的输入:";
	cin >> temp;
	for (int i = 0; i < INT_MAX; i++)
	{
		if (temp == '@')
		{
			break;
		}
		if (isdigit(temp))
		{
			cin >> temp;//是数字还要输入
			continue;
		}
		if (islower(temp))
		{
			temp = toupper(temp);
		}
		else if(isupper(temp))
		{
			temp = tolower(temp);
		}
		cout << temp ;
		cin >> temp;
	}
	return 0;
}
#endif
#pragma endregion

这里要注意如果判断是数字的情况,不是直接继续下一轮循环,而是先接受输入在循环,应为循环就要判断,不接受输入是数字永远是数字,就会进入死循环
效果演示
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值