功能

主要是拿来判断输入的字符是否是为 0 ~ 9 的数字。
(还是那句话,刷题的话知道这个就够用了哈,想深入了解的小伙伴可以自行搜索)

那具体如何使用?很简单根据下面的实例就和容易学得会

实例:

#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
char c1='A';
char c2='1';
if (isdigit (c1)!=0 )
{
cout<<c1<<" is the valid digit!"<<endl;//当c1为0~9d的数字时,打印信息
}
else
{
cout<<c1<<" is not the valid digit!"<<endl; //当c1为非0~9d的数字时,打印信息
}

if (isdigit (c2)!=0 )
{
cout<<c2<<" is the valid digit"<<endl;//当c1为0~9d的数字时,打印信息
}
else
{
cout<<c2<<" is not the valid digit!"<<endl; //当c1为非0~9d的数字时,打印信息
}

return 0;
}

在这里插入图片描述

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐