isdigit
函数 <cctype>
int isdigit ( int c )
检查字符是否是十进制数字
检查c是否为十进制数字字符。
十进制数字可以是:0 1 2 3 4 5 6 7 8 9
在c++中,该函数的特定区域的模板版本(isdigit)存在于头文件<locale>中。
☲ 参数
c
将要被检查、转换为int或EOF的字符。
☉ 返回值
如果c确实是一个十进制数字,返回一个不等于零的值(如,true)。否则返回零(即false)。
☣ 示例
/* isdigit example */
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
int main ()
{
char str[]="1776ad";
int year;
if (isdigit(str[0]))
{
year = atoi (str);
printf ("The year that followed %d was %d.\n",year,year+1);
}
return 0;
} |
输出:
The year that followed 1776 was 1777
isdigit用于检查str中的第一个字符是否为数字,因此,一个有效的候选字符将被
atoi转换成一个整数值。。
🍄 另请参阅