Reading notes: C + + Primer (4th edition) and exercises (CH01-CH11) [++++]
Chapter 2nd data and Basic types
1. Integral type
2. Exercise: Left and right values
3. C + + keyword/reserved word and operator substitution values
4. Declaration, definition, initialization and assignment are different concepts.
A declaration is a description of the existence of a variable that does not allocate memory space for the variable.
The definition is to describe the existence of a variable and allocate the corresponding memory space for that variable.
Initialization is the addition of a meaningful value in the allocated memory space when the variable is defined. If there is no initialization, the variable has a corresponding memory space, but the corresponding content in the memory space is meaningless.
Assignment is the overwrite value of the variable that is already present, that is, the data of the variable memory space is re-erased, and the new data is filled in.
Because of the existence of classes in C + +, the initialization is more finely divided into direct initialization and replication initialization.
C + + provides some rules for initializing variables: Built-in types are not the same as class types, built-in types are automatically initialized to 0 outside of the function body, and the body of the function is not initialized. The class type, in other words, is the default constructor of the calling class.
5. Initialization of const variables/objects
6. The reference declaration must be initialized and cannot be changed once initialized.
You cannot use a const variable to initialize a non-const reference.
7. Defining variables and defining class member variables is not the same.
3rd standard library Type
Read and write 1.string objects
The following code can read the words continuously from the input.
int main () {
string Word;
while (Cin>>word)
cout<<word<<endl;
}
The approximate output of the above program is this:
If you read from the standard input, the result is this: the output is generated after each hit of the ENTER key. The primary CIN reads input from the buffer, and the buffer is refreshed only every time the ENTER key is pressed.
If you're using a pipeline for input, the result is this.
You can see that the words are divided by whitespace characters (spaces, carriage returns, tab characters). The end is judged based on the file terminator.
Getline is used as follows:
int main () {
String line;
while (Getline (Cin,line))
cout<<line<<endl;
}
8. Bitset Type
4th chapter Arrays and pointers
1. Pointers and references
2. Initialization of dynamic arrays
5th Chapter Expressions
1. A predecessor or a post operator in C + +
2. The default initialization when creating objects dynamically.
3. Delete the const object and use Delete to recover the memory
4. Type conversions in C + +
6th Chapter Statement
1. Standard library Exceptions
7th Chapter function
1. The form participates in the argument: The parameter is a variable and the argument is an expression.
2. Const parameter
For C + + built-in types, the addition of Const is not affected by the way the value is copied.
If the formal parameter is a reference, the use of const and non-const is not the case.
3. Const member functions
4. Constructors
Default constructor, constructor initialization list
5. Conversion of argument types
C + + supports function overloading, so there is a function matching problem. In the process of function matching, if the best match is not found, the conversion of the argument type is needed to find the suboptimal match.
6. Const parameters and Overloads
7. Exercise, an enumeration type object can only be initialized with another object of the same enumeration type or an enumeration member.
8. Const reference Formal parameter
The following function is wrong
void swap (const int &A,CONST int &b) {
int tmp=a;
A=b;
B=a;
}
The use of const here is to prevent modifications to incoming parameters.
The following function is also an error:
void swap (const int *A,CONST int *b) {
int tmp=*a;
*a=*b;
*b=tmp;
}
The function of const is to show that the pointer is read-only and is not allowed to be modified.
The different ways of function pointers in 9.c++
When a function overload exists, the function pointer must be precisely matched
8th Standard IO Library
1. The inheritance relationship of the Io stream class and the header file in which it resides
2. IO objects cannot be copied or assigned
3. The most important feature of Io flow in C + + is the state of the stream, which can be determined by judging the state of the stream
4. Use of File stream objects
9th Chapter Sequential Container
1. Types defined in the sequential container
2. Swap operation saves the cost of deleting elements
3. Vector container Self-growth
5. Substr,append and replace operations in string
6. String type of operation, this is actually very important, you can use this kind of find operation to do a lot of work.
Here are some examples of string lookup functions:
View Code
View Code
The following procedure is not strictly the case of this exercise program, the program just finds one word at a time.
View Code
10th Chapter related Containers
Associative containers in 1.STL
Added Unordered_map,unordered_set,unordered_multimap,unordered_multiset in c++11. These four containers are actually common hash_map,hash_set, Hash_multimap, Hash_multiset
2. Pair type
3. Type of map container definition
The reference to the map iterator gets the pair type
4. The special point of map subscript access
5. Insert operation for map
A simple procedure for counting the number of words:
View Code
6. Find operations in Map: Count and find functions
7. A simple word conversion program
View Code
The results of the operation are as follows:
8. Map,set,list Differences
9. Definition and use of Set
10. Use set to rule out some common words so that you avoid common words when counting
View Code
11. Integrated Application of Containers: Text query procedures
View Code
With this program source file as input, there is the following output:
12. Common Common Container Summary
11th-Generic algorithm
1. Inserting iterators
2. iostream iterators
3. Write the file to the output using the copy algorithm:
View Code
4. Three types of iterators
5. Iterator classification
Reading notes: C + + Primer (4th edition) and exercises (CH01-CH11) [++++]