C ++ Study Notes (1)
This learning note is C ++ primer plus (version 6. You can view basic C ++ knowledge.
For more information, see http://www.cnblogs.com/zrtqsk/p/3874148.html. thank you! As follows.
Chapter 1
1. pre-processor -- # include <iostream> adds the content of the iostream file to the program. The old-fashioned C header file retains the extension. h, while the C ++ header file does not have the extension.
(Some C header files are converted to C ++ header files, removing the extension, and adding c, such as cmath)
2. namespace -- equivalent to the package in Java, and the using compilation command is equivalent to the import in Java. When the header file does not have a. h prefix, classes, functions, and variables are standard components of the C ++ compiler and are placed in the namespace std.
3. The essence of a class: class is a user-defined data type. The class definition describes the data format and usage, while the object is an object created according to the data format specification.
4. the return value (exit value) of main () -- main () is returned to the operating system. Generally, if the exit value is 0, the program runs successfully.
Chapter 2
5. OOP-the essence of object-oriented programming is to design and expand your own data types to match the types and data.
6. Identifier-the name starting with an underscore is reserved for implementation as a global identifier; the name of a letter with two underscores or underscores is reserved for implementation (compiler and its resources).
(C ++ has no limit on the name length)
7. Integer -- short must be at least 16 bits; int must at least be the same as short; long must be at least 32 bits and at least as long as int; long must be at least 64 bits and at least as long.
8. bytes-bytes are usually eight-bit memory units, while the bytes in C ++ depend on the implementation.
9. Operator-the operator is a built-in language element. The sizeof operator returns the length (in bytes) of the type or variable ). Therefore, the sizeof (int) return values may be different in different systems.
10. header file climits-defines various symbolic constants that indicate type restrictions. For example, # define INT_MAX 32767. (Designed as a header file available for C, the symbol constant must be defined using the # define compilation command)
11. Variable initialization --
The variable defined in the function should be initialized at the time of definition. Otherwise, its value is uncertain and the value saved for the corresponding memory unit before being created.
(1), int a = 1; // traditional C Initialization
(2 ),Int B (2 );// New method of c ++
(3) int c = {3} or int c {3} // the braces in C ++ are used for any type (when the braces do not contain anything, variable Initialization is 0)
12. int: the maximum length of a computer's processing efficiency. Unless the suffix or value is too large, C ++ usually stores the integer constant as an int type.
13. wcha_t -- it is an integer type and has enough space to indicate the maximum extended character set used by the system. Use wcin and wcout in iostream to process wcha_t streams.
You can use the prefix L to indicate wide character constants and wide strings, such as wcha_t a = L 'P'; wcout <L "tall" <endl;
(The New char16_t and char32_t types in C ++ 11 are all unsigned, with 16-bit length and 32-bit length respectively. The former is prefixed with u, and the former is prefixed with U)
14. bool -- C ++ interprets 0 as false and non-zero as true.
15. const -- it is best to assign values immediately when creating a constant, for example, cont int a = 5; a constant usually uses uppercase letters.
16. floating point -- float must be at least 32 bits; double must be at least 48 bits, and not less than float; long double must be at least as many as double. The index ranges from-37 to 37.
(1) cout. setf () can control the output format and force cout to use the fixed-point notation. Because cout usually deletes the value 0 after the floating point, for example, 3.3300000 is displayed as 3.33.
(2) A floating-point constant is usually of the double type. Generally, the float type is specified with the suffix f or F, and the long double type is specified with the suffix l or L.
17. Forced type conversion --
For example: (long) thorn or long (thorn)
The forced type conversion does not modify thorn itself, but creates a new value of the specified type.
You can also: static_cast <long> (thorn), which is stricter than the traditional forced type conversion.
18. auto -- automatically deduce the type. The keyword auto can not specify the type of the variable. The Compiler automatically sets the type of the variable to be the same as the initial value, for example, auto a = 100;
However, auto is generally used to process complex types.
Chapter 4
19. array --
(1) Declare the general format of the array: typeName arrayName [arraySize], for example, int a [5];
(The Compiler does not check whether the subscript used is valid .)
(2) If no array defined in the initialization function is available, the element value is the value previously resident in the memory. (Same as the variable in the function)
(3 ),When sizeof is applied to the array name, the number of bytes in the entire array is obtained.. When it acts on an element, the number of bytes of the element is obtained.
(4). Initialization is performed only when the array is defined. Partial Initialization is allowed, for example, int a [5] = {1, 2}. During partial initialization, the compiler sets other elements to 0.
It can be like this: int B [] = {1, 2, 3, 4, 5}; let the compiler calculate the number of elements.
(5) When you use the list to initialize an array, You can omit the equal sign (=). When the braces do not contain any content, all elements are 0 by default. The list initialization prohibits the narrow conversion.
20. String --
A string is a series of characters stored in consecutive bytes of the memory.
(1) a C-style string ends with an empty character and its ASCII code is 0, for example, char dog [7] = {'A', 'B ', 'C', 'D', 'E', 'F', '\ 0'}; note that the array length must be calculated as' \ 0'
(2) string constants, such as char cat [] = "cat ";
(Note! 'S' indicates the character constant, while "S" indicates a string consisting of 's' and '\ 0'. "S" actually indicates the memory address of the string)
(3) When splicing a string, the '\ 0' at the end of the first string will be replaced by the first character of the second string.
(4) strlen () function returns the length of the string stored in the array, including only visible characters, not empty characters.
(5) cin uses spaces (spaces, tabs, and line breaks) to determine the end position of the string. Therefore, when it reads the array input, it only reads the first word and automatically adds null characters.
(6) Row-oriented inputs include getline () and get (). They all use line breaks to determine the end of the input. The difference is that get () does not read or discard line breaks.
Cin. getline (name, ArSize), reads ArSize-1 characters into the name array. For get (), you can use: cin. get (name, ArSize). get ();
(7) When an empty row is read, get () sets an invalid bit. If the number of characters contained in the input row is greater than the specified number, getline () sets an invalid bit. The subsequent input is blocked.
(8). Allowed: char c [] = {"hello world! "};
(9) The string class has the function of automatically adjusting the size, so it is more secure.
(10), strcpy (str1, str2) Copy str2 to str1, strcat (str1, str2) and append str2 to the end of str1.
(11), str1.size (), and strlen (str1) have the same functions. The former is a method of the string class, and the latter is a regular function.
21. Original (raw) string-in the original string, \ n does not represent a line break, for example, the default delimiter (and) cout <R "(don't use" \ n ", OK ?) "<'\ N'; output: don't use" \ n ", OK?
Custom delimiters + * (and) + * cout <R "+ * (" (don't use "\ n", OK ?) ") + *" <'\ N'; output: "(don't use" \ n ", OK )"
22. Structure --
(1) Definition: struct man {char name [20]; double weight; int age ;};
(2) Declaration. keywords such as man mike can be omitted;
(3) initialization: man mike {"mike", 56.2, 22 };
(4) use the member operator (.) to access each member.
(5) define the structure and create variables simultaneously: struct man {char name [20]; double weight; int age ;}mike = {"mike", 56.2, 22 }, jim;
(6) You can also declare an anonymous structure: struct {int x, int y} point;
23. Bit Field in the Structure -- specify the structure member that occupies a specific number of digits, for example, struct my_bit {unsigned int x: 4; bool y: 1 ;};
24. External Declaration-External Declaration of the function. C ++ does not advocate the use of external variables or external declarations.
25. shared body --
A data format that can store different data types, but can only store one of them at the same time. It is often used to save memory. For example, union id {long long_id; char char_id ;};
(1) because the shared body can only store one value at a time, its length is the length of the maximum member.
(2) If the Anonymous share body has no name, its members will become variables at the same address, and each time only one member is the current member.
26. enumeration --
Another method for creating symbolic constants can replace const. For example, enum spectrum {a, B, c, d, f };
(1) by default, a, B, c, d, and f are symbol constants, corresponding to 0 to 4.
(2) For enumeration, only the value assignment operator is defined, and no arithmetic operation is defined.
(3) You can only assign the enumeration quantity used for defining enumeration to enumeration variables.
(4) You can use the value assignment operator to explicitly set the enumerated value. For example, enum bits {first, zero = 0, two = 200, three, four}; // the value of three is 201, and the value of first is 0.
(5 ),Enumerated value range. The maximum value of bits is 202, and the power of 2 is 256, so the value range of bits is 0-255.
(6) Add a valid value that can be assigned to the enumerated variable through forced type conversion, as long as it is within the value range. For example, bits B = bits (240 );
27,Pointer--
A pointer is a variable that stores the value address rather than the value itself.
(1). The address operator (&) can obtain the location of the variable (storage address ).
(2) pointer, which regards the address as the specified amount and the value as the derived amount. The pointer name indicates the address.
(3). * operators are called indirect value (unreferencing) operators. Used as a pointer to obtain the value stored in the pointer address.
(4) Declaration: int * a; // The spaces on both sides of the * operator are optional int * B, c; // create pointer B and int variable c, each pointer requires *
(5) initialization: int * a = & B; // set the value of pointer a to & B
(6 ),Before using the unreferenced operator (*) for a pointer, initialize the pointer to a definite and appropriate address.
(7) assign a number to the address: int * pt = (int *) 0x8000000;
(8) memory allocation: int * pn = new int; // allocate memory from the heap or only the memory area of the free store.
28. array --
(1) The Memory allocated to the array during compilation is called static concatenation. when running the program, the length of the array is called dynamic concatenation.
(2) create a dynamic array: int * p = new int [10]; // p indicates the address of the first element of the element.
(3) release the array: delete [] p; // only the memory allocated by new can be released; delete is not allowed twice; delete is secure for NULL pointer; delete [] is used to release the array.
(4 ),The sizeof operator cannot be used to determine the number of bytes contained in the dynamically allocated array.
(5) array: p [0] is the first element, and p [1] is the second element. // C ++ internally uses pointers to process arrays. p [1] is considered as * (p + 1)
(6), p = p + 1; // After the pointer variable is added with 1, the increase is the number of bytes to which it points.
(7) In most cases, C ++ interprets the array name as the address of the first element of the array.
(8) differences between pointer and array name: you can modify the value of the pointer, while the array name is a constant;Use sizeof to get the number of bytes of the array, and use sizeof to get the length of the pointer..
(9), short tell [10];Cout <tell;// The array name itself is the address of its first element, for example, & tell [0], which is the address of a 2-byte memory block.
Cout <& tell;// Output a 20-byte memory block address.
(10) provide a character address for cout. It will be printed from this character until it encounters an empty character.
(11) to print the address of a pointer, the pointer must be strongly converted to another pointer type, such as (int *) p;
29. Use new to create a dynamic structure -- struct1 * s = new struct1; // at this time,The structure identifier is a pointer, so the Member operator period (.) cannot be used (.),
// Only the arrow member operator (->) can be used to access members or (* s). price can be used to access members.
30. Automatic Storage, static storage, and dynamic storage --
(1) the common variables defined in the function are automatic variables, which are stored in the stack, followed by LIFO, which keeps increasing and decreasing during program execution. For automatic storage.
(2) define the variable outside the function, or declare the variable using the static keyword as a static variable. Static storage is a variable that exists throughout the execution period of the program.
(3) use the new variable for dynamic storage. New and delete manage a memory pool, called free store or heap.
(Note! The stack auto-increment and deletion mechanism keeps the occupied memory continuously, while new and delete may cause only the storage area to be discontinuous)
31. The template class vector-similar to string, is also a dynamic array. It is a substitute for creating a dynamic array using new and automatically managing the memory using new and delete.
# Include <vector> using namespace std; // contains the header file. The vector is located in the std namespace.
Vector <int> ele (10); // create a vector object named ele, which can store 10 int-type elements.
(Note: List Initialization is available in C ++ 11. Type can be a variable)
32. template class array-same as array, with fixed length, using Stack storage, the efficiency is the same as array, and it is more convenient and secure.
# Include <array> using namespace std; array <int, 5> arr; // an array object named arr, which contains five int elements.
(Note: The type cannot be a variable! Available List initialization)
Senior One, compulsory one, math study notes, and summary
Chapter 1 set and function concepts
1. concepts related to collections
1. Meaning of a set: some specified object sets become a set, and each object is called an element.
2. Three features of elements in a set:
1. Element certainty; 2. Interaction of elements; 3. Element disorder
Note: (1) for a given set, the elements in the set are definite. Any object or element that is not the given set.
(2) Any two elements in a given set are different objects. When the same object falls into a set, only one element is involved.
(3) The elements in the set are equal and there is no sequential order. Therefore, to determine whether the two sets are the same, you only need to compare whether their elements are the same. You do not need to check whether the order is the same.
(4) The three features of a set element make the set itself deterministic and integral.
3. Representation of the set :{... } For example, {basketball players in our school}, {Pacific, Atlantic, Indian Ocean, and Arctic Ocean}
1. Use A Latin letter to indicate the set: A = {basketball players in our school}, B = {1, 2, 4, 5}
2. The expression of the set: the column method and the description method.
Note: Common number sets and their recording methods:
A non-negative integer set (that is, a natural number set) is recorded as N.
Positive Integer Set N * or N + Integer Set Z rational number set Q real number set R
The concept of "belonging"
The elements of a set are usually represented by lowercase Latin letters. For example, if A is an element of a, A belongs to a of the set and is recorded as A, a, on the contrary, a does not belong to set.
Column partitioning: lists the elements in the set one by one, and then enclose them in braces.
Description Method: describes the common attributes of elements in a set and describes the set in braces. Use a definite condition to indicate whether some objects belong to this set.
① Language description: Example: {triangle not a right triangle}
② Mathematical formula subdescription method: for example, the solution set of inequality X-3> 2 is {x R | X-3> 2} or {x | X-3> 2}
4. Classification of sets:
1. a finite set contains a finite element.
2. An infinite set contains a set of infinite elements.
3. Examples of empty sets without any elements: {x | x2 =-5}
2. Basic Relationship between Sets
1. "include" link-subset
Note: There are two possibilities: (1) A is part of B; (2) A and B are the same set.
Conversely, set A does not contain Set B, or set B does not contain Set A, which is recorded as a B or B.
2. "equal" relationship (5 ≥ 5, and 5 ≤ 5, then 5 = 5)
Instance: Set A = {x | x2-1 = 0} B = {-} "same element"
Conclusion: For two sets A and B, if any element of Set A is an element of Set B, and any element of Set B is an element of set, let's say that set A is equal to Set B, that is, A = B.
① Any set is a subset of itself. A branch
② True subset: If A contains B and A contains B, it means that set A is the true subset of Set B and is recorded as a B (or B)
③ If A between B and B between C, then A between C
④ If A between B and B between A, then A = B
3. A set without any elements is called an empty set, which is recorded
Rule: An empty set is a subset of any set, and an empty set is a real subset of any non-empty set.
Iii. Set Operations
1. Intersection definition: Generally, A set composed of all elements A and B is called the intersection of A and B.
It is written as A transaction B (read as "A to B"), that is, A transaction B = {x | x, A, and x, B }.
2. Definition of Union: Generally, A union of all elements of A or B is called A and B. As A member B (read as "A and B"), that is, A member B = {x | x, A, or x, B }.
3. The nature of intersection and Union: A between A = A, A between Phi = Phi, A between B ...... the remaining full text>
Note 1 what does the EU do
Therefore, I had to study the EU knowledge diligently. I would like to share with you. Reference books are The EU overview of The Eruopean Union published by The Institute of Foreign Affairs. The original author is John Pinder. Translator, Dai bingran. First, take a vocabulary note. Let's take a look at the European Union's ancestor: ECSC and European Coal an Steel Community. Remember that the short term is very important. For example, this interpreter took the UNFCCC test. What we know is that EU has evolved from ECSC over the years. What about EU, formerly known as the European community, EC, and European community. The European Community has six founding countries. France, Germany, Belgium, Luxembourg, Italy, and Holland. In 1958, EEC and European economy Community were established to serve as the European Economic Community. To understand the EU, it is very important to understand some documents and treaties during the establishment of the EU. Today, we first see the Schulman Declaration Shuman Declaration. This year marks the 60 th anniversary of the Shuman declaration. Let's look at what is the Shuman declaration. --- The following is a reference-in May 9, 1950, Shuman published the famous European integration declaration, providing ideas for the establishment of the EU. Shortly afterwards, led by France, the predecessor of the European Union, the European coal-steel community, was established. Schulman suggested that a "super-national" organization be established to plan and lead coal and steel production in France and Germany, namely Schulman plan ). At the core of the Shuman plan is to put the entire production of coal, iron, and steel in France and Germany under the management of a high-level institution beyond the country, and the Organization opens its doors to other European countries. The plan received responses from the Federal Germany, Italy, Belgium, the Netherlands and Luxembourg. The six countries signed the European Coal and Steel Joint Venture Treaty (also known as the Paris Treaty) for a period of 50 years in Paris, France on April 18, 1951. on the basis of the Treaty, the European Coal and Steel Community (ECSC) was established ). Since then, countries have sought greater cooperation and have decided to give priority to strengthening cooperation in the economic field rather than in the political field. Economies of all countries can be more closely linked by establishing economic organizations that participate together. The Schuman Plan laid the foundation for the European Coal and Steel Union and the defense community. Schuman, as the "father of Europe", will always be recorded in history. --- End of the quote --- According to Su's book, the initial purpose of the founding is actually to ensure a lasting peace in Europe, that is, durable peace. In the Second World War, Europe suffered a rare war disaster, while Germany and France frequently joined forces, so they wanted to be more peaceful in Europe. In addition to political purposes, without economic strength and prosperity, this community will not be very successful.