1. member functions. Cout.put (), Cout.put () is an important c++oop concept-the first example of a member function---. class defines how to
Representation and control of data, member functions are categorized in all, describing the method of manipulating class data. For example, class Ostream has a put () member function,
Used to output characters, you can use member functions only through specific objects of a class, and to use member functions through an object, you must use a period object name and a letter
Several names, (put ()) are connected together. A period is called a member operator. Cout.put () means that the class object cout is used to
function put ().
The 2.cout.put member function provides another way to display characters, instead of the << operator. Before the Releasc2.0 of C + +,
cout displays character variables as characters and character constants (such as M and N) as numbers. The problem is that earlier versions of C + + will have the same
Character constants are stored as int types. That is, M's code 77 will be stored in a 16-bit or 32-bit unit. Char variables typically account for 8 bits
The following statement copies 8 bits from the constant m (8 bits to the left) into the variable ch:
Char ch= "M";
Unfortunately this means that for cout, M and ch look a huge difference. Although they store the same values, the following statement will print the
ASC11 code, not character $;
cout << "$";
But the following statement will print the character $:
Cout.put ("$");
After Release2.0, C + + stores character constants as char types. Instead of an int type. This means that cout can now handle characters correctly
Constant.
The CIN object has several different ways to read the input characters. By using a program that uses loops to read several characters,
3. In C + +, there are many ways to write character constants, and the simplest way for regular characters is to enclose the word trailing characters in quotation marks, a notation
Represents the numeric encoding of the character. For example, the corresponding situation in the ASC11 system:
A.A is 65, which is the ASCII code of character A.
B.A is 97, which is the ASCII code of character A.
C.5 is 53, which is the ASCII code of character 5.
D. "" Is 32, which is the ASCII code of the space character.
E. "! "33, which is the ASCII code of the exclamation point.
This notation is better than numerical coding, he is clearer, and does not need to know the encoding method, if the system uses the EBCDIC, then A's encoding will not be 65
But "a" still represents the character a.
4. Some characters cannot be entered directly into the program via the keyboard. For example, pressing ENTER does not allow a string to contain a line break: Instead, the program edits it to
This keystroke is represented as starting a new line in the main source code, and some other characters cannot be entered from the keyboard because the C + + language gives them special
Meaning. For example, double-quote characters are used to separate string literals, so double quotation marks cannot be placed in string literals. For these characters C + + extracts
A special form of expression---escape sequence.
Preparation knowledge of C + + 11