c++ string is digit code example

Example 1: c++ is string a number

bool isStringNumber(string str){
for(int i=0;i<str.length();i++){
if(str[i]<'0'||str[i]>'9'){
return false;
}
}
return true; 
}
//Beleive in Allah!
//just my slogan

Example 2: check if character in string is digit c++

#include<stdio.h>
#include<ctype.h>

int main() {
   char val1 = 's';
   char val2 = '8';

   if(isdigit(val1))
   printf("The character is a digit\n");
   else
   printf("The character is not a digit\n");

   if(isdigit(val2))
   printf("The character is a digit\n");
   else
   printf("The character is not a digit");

   return 0;
}

Tags:

C Example