Bibliothèque de paramètres régionaux C ++ - isdigit

La description

Il vérifie si le caractère est un chiffre décimal.

Déclaration

Voici la déclaration pour std :: isdigit.

C ++ 98

int isdigit ( int c );

C ++ 11

int isdigit ( int c );

Paramètres

c - Caractère à vérifier, transtypé en un entier ou EOF.

Valeur de retour

Il renvoie une valeur différente de zéro.

Exceptions

No-throw guarantee - cette fonction ne lève jamais d'exceptions.

Exemple

Dans l'exemple ci-dessous pour 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;
}

L'exemple de sortie devrait être comme ceci -

The year that followed 2016 was 2017.