The classic order "Hello World"
Every language learner knows that C + + is one of the hardest languages, but there is also a sentence that is learning C + + Other languages three days can learn, which although a bit exaggerated but also shows the importance of C + +, it weighs on the exercise of thought, So no matter what language you study in the future, I think we should have a certain understanding of C + +, let's learn it together today.
Let's start our learning path from this classic C + + program.
This is a C + + program
#include <iostream>usingnamespace std; int main ()//main function { cout<<"helloWorld"<<
return 0; }
The first line is a C + + program style annotation, which starts with "//", ends at the end of each line, and can be:/* This is a C + + programs */This form of comments, comments on the operation of the program does not work, but good programs should have clear comments, is the program reading easy to understand.
The second line of "#" is a precompiled command that requires the compiler to embed the iostream file into the source file containing the # include command, including the command,< file name, which is generally referred to as the header file, which is the system header file, if the header file is written by itself "", The file iostream contains information about input and output (I/O) defined by the C + + system, and the information about the cout and operator << is declared in the file.
The third line is usually used in standard C + + library files should be added, it means "using namespaces."
The rest of the following is the most important part, int is a type, after the question of the type of detail, first know that it is a shape, main function, also can be said to be a function name, about the function of the big problem will be a little detail in the back, now we just need to know that each program has a main function, This is a program the most important place, without his program can not run, the function is () This is the place to put parameters, simply say you think with this function of the number, the function behind the {} is the function body, is what function can be in here,
int Main () { // function Body }
This is a pattern, as is the case with subsequent functions.
Now is the function body part of the introduction, where ' cout ' is the meaning of the screen, but also the output symbol, the following operator "<<" to see its direction can be understood as the meaning of the output to the screen, the end of the Endl represents a newline character in the output stream.
The return in the next line is returned when its value is 0 to prove that the program is running correctly, and if it returns not 0, it cannot run. It is also the result of running the function back into the program. At the same time the program is composed of statements, each statement by a semicolon (;) as a terminator, in this case there are two statements.
Finally, a program is completed to pass: Edit, compile, connect, the last is the execution, so a program error there may be a process in this is wrong, to carefully examine.
Turn on the C + + path