The escape sequence
\n (backward slash and the letter n) generates a new line in a text string.
The program runs line by line, from top to bottom:
- The first line instructs the compiler to locate the file that contains a library called
iostream. This library contains code that allows for input and output.
main()function houses all the instructions for the program.
std::cout is the “character output stream” and it is used to write to the standard output. It is followed by the symbols
<< and the value to be displayed.
Using GNU, the compilation command is
g++ followed by the file name. Here, the name of the source file is hello.cpp.
The execution command is
./ followed by the file name. Here, the name of the executable file is a.out.
Single-line comments are created using two consecutive forward slashes. The compiler ignores any text after
// on the same line.
Multi-line comments are created using
/* to begin the comment, and
*/ to end the comment. The compiler ignores any text in between.