C++ 本地化庫 - isdigit



描述

它檢查字元是否為十進位制數字。

宣告

以下是 std::isdigit 的宣告。

C++98

int isdigit ( int c );

C++11

int isdigit ( int c );

引數

c − 要檢查的字元,轉換為 int 型別,或 EOF。

返回值

它返回一個非零值。

異常

無異常保證 − 此函式從不丟擲異常。

示例

以下為 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.
locale.htm
廣告
© . All rights reserved.