#include #include using namespace std; int main() { char str[31];//定义字符数组 cin>>str;//输入字符串 int len=strlen(str);//计算字符串长度 for(int i=0;i<len-1;i++)//注意:字符串以#结束,要减去最后一个字符 { if(str[i]>='a'&&str[i]<='z')//小写字母转大写 cout<<char(str[i]-'a'+'A');//输出大写字母 else if(str[i]>='A'&&str[i]<='Z')//大写字母转小写 cout<<char(str[i]-'A'+'a');//输出小写字母 else cout<<str[i];//其他字符直接输出 } cout<<endl;//输出换行 return 0; }

C++ 字符串大小写转换程序:将小写字母转大写,大写字母转小写

原文地址: https://www.cveoy.top/t/topic/mGFJ 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录