C++ 字符串大小写转换:将小写字母转换为大写,大写转换为小写
#include
int main() { char str[31]; cin.getline(str, 31, '#'); // 读入字符串 for (int i = 0; str[i] != '\0'; i++) { if (str[i] >= 'a' && str[i] <= 'z') { // 如果是小写字母 str[i] -= 32; // 转换成大写字母 } else if (str[i] >= 'A' && str[i] <= 'Z') { // 如果是大写字母 str[i] += 32; // 转换成小写字母 } } cout << str << endl; // 输出转换后的字符串 return 0; }
原文地址: https://www.cveoy.top/t/topic/mGGv 著作权归作者所有。请勿转载和采集!