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; }
|