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

    科技2025-10-13  2

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

    例子如下

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

    tolower 就是转换为小写

    toupper就是转换为大写

    例子如下

    #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; }
    Processed: 0.017, SQL: 8