C + + pre-defined character functions

Source: Internet
Author: User

Use the Get member function to read all characters in a file, including whitespace characters, end of file.
Use >> to read files and automatically ignore whitespace characters (spaces, line breaks, tabs)

C + + predefined character functions (all defined in the Cctype library):
ToUpper (Char_type) returns the uppercase form of the Char_type
ToLower (char_type) returns the lowercase form of char_type
Isupper (Char_type) If Char_type is uppercase, returns true
Islower (Char_type) If Char_type is lowercase, returns true
Isalpha (Char_type) If Char_type is a letter, return true
IsDigit (Char_type) If the Char_type is a ' 0 '-' 9 ' number, the return True
Isspace (Char_type) If the char_type is a blank character (space, line break), returns True

For example, the following code reads a sentence ending with '. ' and then replaces all spaces with '-' Display

650) this.width=650; "alt=" Copy Code "src=" Http://common.cnblogs.com/images/copycode.gif "/>

1 char ch;2 do{3 cin.get (CH); 4 if (Isspace (CH)) 5 cout << '-'; 6 else7 cout << ch;8 }while (ch! = '. ');

650) this.width=650; "alt=" Copy Code "src=" Http://common.cnblogs.com/images/copycode.gif "/>

Note: Because the computer store characters are stored with their ASCII code, in digital form, plus the C + + output stream cout Automatic recognition type, the following example outputs a number, not a character:

1 cout << toupper (' a ');

To output characters, you can use the following two ways:
One: Convert with coercion type

Static_cast<char> (ToUpper (' a '));

Two: Receive the value of ToUpper with a character variable, and then output:

1 Char ch = toupper (' a '); 2 cout << ch;


This article is from the "_ Conan conan_" blog, please be sure to keep this source http://goodhx.blog.51cto.com/9727085/1735117

C + + pre-defined character functions

Related Article

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.