当前位置:首页 C++ > 正文

c++isdigit函数

作者:野牛程序员:2023-08-17 09:34:27 C++阅读 2733

isdigit函数也可以在C++中使用,其头文件是<cctype>

以下是一个在C++中使用isdigit函数检查字符是否为数字字符的简单示例:

#include <iostream>
#include <cctype>

int main() {
    char ch = '7';

    if (std::isdigit(ch)) {
        std::cout << ch << " is a digit." << std::endl;
    } else {
        std::cout << ch << " is not a digit." << std::endl;
    }

    return 0;
}

在这个例子中,包含了<iostream><cctype>头文件。然后,使用std::isdigit函数来检查字符是否为数字字符,并使用std::cout输出相应的信息。


野牛程序员教少儿编程与信息学奥赛-微信|电话:15892516892
野牛程序员教少儿编程与信息学竞赛-微信|电话:15892516892
相关推荐

最新推荐

热门点击