跳到主要内容

C++ islower() 判断字符是否为小写字母

islower() 原型

int islower(int ch);

islower() 函数用于检查 ch 是否为小写字母,这是根据当前 C 语言区域设置分类的。默认情况下,从 a 到 z (ASCII 值 97 到 122)的字符被视为小写字母。

如果 ch 的值无法表示为 unsigned char 或不等于 EOFislower() 的行为是未定义的。

它定义在 <cctype> 头文件中。

islower() 参数

ch:要检查的字符。

islower() 返回值

如果 ch 为小写字母,islower() 函数返回非零值;否则返回零。

示例:islower() 函数如何工作

#include <cctype>
#include <iostream>
#include <cstring>

using namespace std;

int main()
{
char str[] = "This Program Converts ALL LowerCase Characters to UpperCase";

for (int i=0; i < strlen(str); i++)
{
if (islower(str[i]))
/* 将小写字符转换为大写 */
str[i] = str[i] - 32;
}

cout << str;
return 0;
}

当你运行程序时,输出将是:

THIS PROGRAM CONVERTS ALL LOWERCASE CHARACTERS TO UPPERCASE