例题描述:
编写一个程序,读取键盘输入,直到遇到@符号为止,并回显输入(数字除外),同时将大写字母转换为小写,将小写字母转换为大写(使用cctype)。
实现如下:
#include<iostream>
#include<string>//用string类的对象来存储变换后的字符串
#include<cctype>//常用的字符函数库
using namespace std;
int main(){
char ch;
string str = "";
cout<<"请输入字符: ";
cin>>ch;
while (ch != '@'){
cin>>ch;
if ((isdigit(ch))-1){//判断是否是数字{
if(isalpha(ch)){
if(isupper(ch)){
ch = tolower(ch);
}
else{
ch = toupper(ch);
}
}
str = str + ch ;
}
}
cout<<"the output is: "<<str<<endl;
return 0; }