1、string 类字符串
可以对既含有大写字母又含有小写字母的字符串全部进行转化
#include <algorithm> // 头文件
string str;
transform(str.begin(), str.end(), str.begin(), ::tolower); // 大写转小写 to lower
transform(str.begin(), str.end(), str.begin(), ::toupper); // 小写转大写 to upper
2、char 字符数组
只能用 tolower(c) 和 toupper(c) 对单个字符一一转换
#include <algorithm>
#include <cstring> // 头文件
char s[20];
for(int i = 0; i < len; i ++)
if(s[i] >= 'A' && s[i] <= 'Z')
s[i] = tolower(s[i]); // 大写转小写 或 s[i] += 32;
for(int i = 0; i < strlen(s); i ++)
if(s[i] >= 'a' && s[i] <= 'z')
s[i] = toupper(s[i]); // 小写转大写 或 s[i] -= 32
A:65
a:97