C++ 标准库 - <cctype>

C++ std::tolower 若是大写字母则返回对应小写,否则原样返回。结果仍是 int,写入 char 或 string 前需转换。

原型

int tolower(int ch);

参数

  • ch:按 unsigned char。

返回值

转换后的字符编码。

示例

#include <cctype>
#include <iostream>

int main() {
    char c = static_cast<char>(std::tolower('A'));
    std::cout << c << "\n";
    return 0;
}

输出:

a

注意事项

对整串做大小写转换时,逐个字符调用,注意 char 有符号的问题。

下一页介绍toupper。