以下是C++代码示例,可以将输入的字符串中的小写字母转换为大写字母,大写字母转换为小写字母:

#include #include using namespace std;

int main() { char str[100]; cout<<"Enter a string: "; cin>>str;

for(int i=0;i<strlen(str);i++) 
{ 
    if(str[i]>='a'&&str[i]<='z') 
        str[i]=str[i]-32; 
    else if(str[i]>='A'&&str[i]<='Z') 
        str[i]=str[i]+32; 
} 

cout<<"The converted string is: "<<str; 

return 0; 

}

输入: Enter a string: Hello World

输出: The converted string is: hELLO wORLD

C加加编写大小写转换

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

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