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