首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

在c++中检查字符是大写还是小写

在C++中,你可以使用标准库函数 isupper()islower() 来检查字符是大写还是小写

代码语言:javascript
复制
#include <iostream>
#include <cctype> // 包含 isupper() 和 islower() 函数

int main() {
    char ch;

    std::cout << "请输入一个字符: ";
    std::cin >> ch;

    if (std::isupper(ch)) {
        std::cout << "字符 " << ch << " 是大写字母。" << std::endl;
    } else if (std::islower(ch)) {
        std::cout << "字符 " << ch << " 是小写字母。" << std::endl;
    } else {
        std::cout << "字符 " << ch << " 不是字母。" << std::endl;
    }

    return 0;
}

在这个示例中,我们首先包含了 <cctype> 头文件,它提供了 isupper()islower() 函数。然后我们获取用户输入的字符,接着使用 isupper()islower() 函数来检查字符是否为大写或小写字母。

页面内容是否对你有帮助?
有帮助
没帮助

相关·内容

领券