Determines whether a character is a number
There is isdigit () in C + + to determine whether a character is a number
Prototype: int isdigit (char c);
Usage: #include <ctype.h> (C language), #include <cctype> (c + +)
Function: Determine whether the character C is an Arabic numeral
Determines whether a string is made up of numbers
1 BOOLIsnumber (stringstr)2 {3 for(intI=0; I<str.length (); i++)4 if(!isdigit (Str[i]))5 return false;6 return true;7}
Determine the legitimacy of the input ID number
intCalstringa) { return(a[0] -'0') *7+ (a[1] -'0') *9+ (a[2] -'0') *Ten+ (a[3] -'0') *5+ (a[4] -'0') *8+ (a[5] -'0') *4+ (a[6] -'0') *2+ (a[7] -'0') *1+ (a[8] -'0') *6+ (a[9] -'0') *3+ (a[Ten] -'0') *7+ (a[ One] -'0') *9+ (a[ A] -'0') *Ten+ (a[ -] -'0') *5+ (a[ -] -'0') *8+ (a[ the] -'0') *4+ (a[ -] -'0') *2;}CharSstringa) { intK = Cal (a)% One; if(k = =0) return '1'; Else if(k = =1) return '0'; Else if(k = =2) return 'X'; Else return '0'+ A-K;}intIsid () {stringNumber ; while(Cin >>Number )if( -==number.length () &&isnumber (number))if(number[ -] ==s (number))return True; Elsereturnfalse; Elsecout<<"the input format is not correct, please re-enter:"<<Endl;}
To find the string length
The length of the string can be obtained from both C + + strlen (str) and Str.length () and Str.size ().
where Str.length () and Str.size () are member functions that are used to find a String class object
Strlen (str) is used to find the length of a character array whose parameters are char*.
Some small knowledge in C + +