Cctype header file Definition function instance

Source: Internet
Author: User

Cctype header file contains functions are mainly used to test the character value, the following is a random look for a table, but for beginners, how to use it, their own on the machine operation to solve, the latter two returned to the int type, indeed very unexpected, forced conversion, very simple.

Isalnum (c) True if C is a letter or a number

Isalpah (c) True if C is a letter

Iscntrl (c) True if C is a control character

IsDigit (c) True if C is a number

Isgraph (c) True if C is not a space

Islower (c) True if C is a lowercase letter

Isprint (c) True if C is a printable character

Ispunct (c) True if C is a punctuation mark

Isspace (c) True if C is a blank character

Isupper (c) True if C is a capital letter

Isxdigit (c) True if C is a hexadecimal number

ToLower (c) If C is a capital letter, it returns a lowercase letter, otherwise it returns C.

ToUpper (c) If C is a lowercase letter, return a larger letter form, otherwise return C.

I demonstrate the first and last, more representative.

#include <iostream> #include <cctype> using namespace std;         int main () {char C;     C= ' d ';     if (Isalnum (c)) {cout "C" "is a alpha or number";   else cout "C" "is a not alpha or number"; The output results are shown below: #include <iostream> #include <cctype> using namespace std;     int main () {char C;     c= ' D '; cout Char (ToLower (c));

The ToLower () function returns an integer type, so if you do not overload the function, the correct output is achieved by type conversion, so watch out.

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.