C++ Locale 库 - isdigit
描述
它检查字符是否为十进制数字。
声明
以下是 std::isdigit 的声明。
C++98
int isdigit ( int c );
C++11
int isdigit ( int c );
参数
c − 要检查、转换为 int 或 EOF 的字符。
返回值
它返回一个不同于零的值。
异常
No-throw guarantee − 此函数从不抛出异常。
示例
在下面的 std::isdigit 示例中。
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
int main () {
char str[]="2016ad";
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 2016 was 2017.

