C++ 标准库 - <cctype>

C++ std::isalpha 判断是否为字母。默认 C locale 下即 A-Z、a-z。

原型

int isalpha(int ch);

参数

  • ch:同上,按 unsigned char。

返回值

非 0 表示是字母。

示例

#include <cctype>
#include <iostream>

int main() {
    std::cout << (std::isalpha('Q') ? 1 : 0) << " ";
    std::cout << (std::isalpha('7') ? 1 : 0) << "\n";
    return 0;
}

输出:

1 0

注意事项

空白用 isspace,字母或数字用 isalnum。

下一页介绍tolower。