I. Basic Knowledge
1. A class is a data type that combines data and algorithms.
2. If an uninitialized variable is referenced, an error will occur (the system assigns it a random value, which is related to the last referenced value of the system and memory ).
3. Two Methods for initialization: ① int I = value; ② int I (value );
4. display the number of decimal places:
Cout. SETF (IOs: fixed );
Cout. SETF (IOs: showpoint );
Cout. preciison (2); // enter the number of digits to display in parentheses
5. Top-Down Design (also becoming a step-by-step refinement or governance );
6. The POW function clock returns the value of the double type, instead of the int type.
7. Force Data Type Conversion
Static_cast <double> (INT variable or value) // The Int data type is converted to double type in the example. This is a relatively new method.
Double (INT variable or value) // This is an old method. We recommend that you use a new method because the old method may not be supported by the compiler in the future.
Ii. Functions
1. After the return statement is executed in the function, the function call ends. Therefore, you can use return to terminate calls in void functions.
2. Overload function name: Define a function with the same name. For example
Double avg_num (double I, Double J)
Double avg_num (double I, Double J, Double K)
Any two functions with the same name must use different numbers of parameters or different types of parameters.
3. Function calling mechanism: ① Value passing call mechanism. ② Upload and reference the call mechanism.
4. the driver is a program specifically used to test a function.
5. Exit (1), exit (0): in UNIX and Windows operating systems, 1 indicates an error, and 0 indicates a success. (This is just a specification)
Iii. I/O Stream
1.to import the input file to the test.txt file, you can use open with two parameters
Ofstream out_sream;
Out_stream.open ("test.txt ");
If the testfile does not exist, a test.txt file will be created. If the file already exists, content will be appended to it.
2. Difference Between CIN> and CIN. Get (): CIN> is automatically converted after processing. It ignores blank characters and returns the carriage return. However, using cin. Get () won't automatically change, and spaces and line breaks will be stored.
3. When a sub-function calls parameters of the ifstream or ofstream type, its address is read_file (ifstream & in_stream ).
4. isalpha (character) // determines whether the character is an English letter
Isdigit (character) // determines whether the character is a number
Isspace (character) // determines whether the character is a space
5. When the input and output streams are used in the function declaration, you need to add the using set after the include
6. Default real parameters in the function: If the function contains default real parameters, they must be placed at the end of the parameter list.
For example, void fun (int I, Int J = 1, int K = 2 );
Iv. String
1. The ending sign of the string array: '\ 0 ';
2. A string with a length of N can contain up to (n-1) characters, and a string is used to store '\ 0 ';
3. The following string assignment is invalid:
Char C [10];
C = "Hello '; // invalid
It is different from the following statement: Char C [10] = "hello"; this is an initialization operation on the string, rather than a value assignment.
Assign values to strings using methods such as strcpy (C, "hello;
4. assign a value to a string type string from the character input on the keyboard. The method is as follows:
String S;
Getline (CIN, S );
If CIN> S is used, only the first consecutive string is obtained. For example, if "Hello world" is input, only hello is input to S;
5. pointers and Arrays
1. The length of a vector refers to the number of elements in the amount, and the capacity of the vector refers to the number of elements actually allocated with memory.
2. A pointer is a structure that allows us to control the memory of our computers.
3. Do not perform Standard Arithmetic Operations on pointers (although they can perform addition and subtraction operations on pointers, they are not ordinary integer addition and subtraction operations );
4. c ++ standard stipulates that if there is not enough memory to create a new variable, the new operator terminates the program by default, unless there is a program event that captures this exception and handles it.