Some small knowledge in C + +

Source: Internet
Author: User

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 + +

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.