isdigit函数

isdigit是计算机C(C++)语言中的一个函数,主要用于检查其参数是否为十进制数字字符。

函数定义:int isdigit(int c)
函数说明:检查参数是否为十进制数字字符(判断括号内是否为0~9的数字。)
函数所需头文件:#include
返回值:若参数c为阿拉伯数字0~9,则返回非0值,否则返回0。

代码示例

//isdigit:判断字符是否为阿拉伯数字0~9#include#include using namespace std; int main(){string str = "123456789asdfghjkl~!@#$%";for(int i = 0; str[i] != 0; ++i){if(isdigit(str[i]))cout << str[i] << " isdigit" << endl;elsecout << str[i] << " is not digit!" << endl;}return 0;}

打印输出

标准输出:0 isdigit1 isdigit2 isdigit3 isdigit4 isdigit5 isdigit6 isdigit7 isdigit8 isdigit9 isdigita is not digit!s is not digit!d is not digit!f is not digit!g is not digit!h is not digit!j is not digit!k is not digit!l is not digit!~ is not digit!! is not digit!@ is not digit!# is not digit!$ is not digit!% is not digit!

引经据典

https://baike.baidu.com/item/isdigit/9455880?fr=aladdin