#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
这里要注意如果判断是数字的情况,不是直接继续下一轮循环,而是先接受输入在循环,应为循环就要判断,不接受输入是数字永远是数字,就会进入死循环
效果演示