Char,String类型类型大小写转换的函数

Char转换

可以使用tolower(char c)转换为小写,toupper(char c)转换为大写

例子如下

1
2
3
4
5
6
7
8
9
#include <iostream>
#include <cctype>
using namespace std;
int main() {
char a = 'a', b = 'A';
printf("%c\n",tolower(b));//把字符转换为小写
printf("%c", toupper(a)); //把字符转换为大写
return 0;
}

String转换

tolower 就是转换为小写

toupper就是转换为大写

例子如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main()
{
string s = "ABCDEFGabcdefg";
string result;
transform(s.begin(), s.end(), s.begin(),::tolower);
cout << s << endl;
transform(s.begin(), s.end(), s.begin(),::toupper);
cout << s << endl;
return 0;
}