1.1 Basic knowledge of C + +
1.1.1 Small program "Hello World"
Annotations, preprocessing directives, main () functions, input/output streams
1. Note: Single-line comments use//Multiline comment/* ...
2. Preprocessing command: Start with a # character, such as: #include <iostream>, function: Extracts all the contents of the <iostream> header file and provides it to the current file. Header file function: Declaring functions defined elsewhere
Note: In C, files that are included usually end with. h, such as <stdio.h>. In C + +, the header file omits this suffix, such as <iostream>. But the standard header file in C still exists in C + +, just changing the name. As:<stdio.h> became a <cstdio>
Table 1-1: Common pre-processing commands
| preprocessing commands |
Function |
Common usage |
| #include [file] |
Inserts the specified file into the code where the instruction is located |
is almost always used to include header files so that code can use features defined in other locations |
| #define [Key][value] |
Each specified key is replaced with the specified value |
In C, it is common to define numeric values or macros. C + + provides better constants and macro-definition mechanisms, and macros are risky to use, so use them sparingly in C + + |
#ifdef [Key] #endif #ifndef [Key] #endif |
The code in IFDEF ("if defined") Block or ifndef ("if not define") is conditionally included or discarded, depending on whether the specified key is defined with a # define |
Often used to prevent loops from being contained. Each contained file begins with #ifndef to determine that a value is not defined, and then defines the value. The included file ends with #endif so that the header file is not included in multiple |
| #pragma [XYZ] |
XYZ varies by compiler. If you perform this instruction during preprocessing, a warning or error message is typically displayed |
Http://www.360doc.com/content/10/0902/09/2795334_50552950.shtml |
3.main (): Program entry, return int value indicates the final execution state of the program, can have no parameters or have two parameters. such as int main (int argc, char* argv[]), where ARGC: arguments to the number of arguments to the program, argv: contains these parameters. Note: argv[0] may be the name of the program, but it should not be relied upon and should never be used.
4. Input/output stream: Std::cin std::cout
1.1.2 namespaces: Used to handle name collisions between different pieces of code. Use directives are used to avoid specifying a namespace, or you can use a using directive to reference a specified item using Std::cout within a namespace. Warning: You cannot use a using directive or a using declaration in a header file, or everyone will include your header file.
1.1.3 Variable
Chapter 1th C + + and STL Express