Because this line starts with a #, it is called a preprocessor directive . The preprocessor reads your program before it is compiled and only executes those lines beginning with a # symbol. Think of the preprocessor as a program that “sets up” your source code for the compiler. The #include directive causes the preprocessor to include the contents of another file in the program. The word inside the brackets, iostream , is the name of the file that is to be included. The iostream file contains code that allows a C++ program to display output on the screen and read input from the keyboard. Because this program uses cout to display screen output, the iostream file must be included. The contents of the iostream file are included in the program at the point the #include statement appears. The iostream file is called a header file, so it should be included at the head, or top, of the program.
usingnamespace std;
Programs usually contain several items with unique names. Variables, functions, and objects are examples of program entities that must have names. C++ uses namespaces to organize the names of program entities. The statement using namespace std; declares that the program will be accessing entities whose names are part of the namespace called std . The reason the program needs access to the std namespace is because every name created by the iostream file is part of that namespace.
int main()
This marks the beginning of a function. A function can be thought of as a group of one or more programming statements that collectively has a name. The name of this function is main, and the set of parentheses that follows the name indicate that it is a function. The word int stands for “integer.” It indicates that the function sends an integer value back to the operating system when it is finished executing. Although most C++ programs have more than one function, every C++ program must have a function called main . It is the starting point of the program. If you are ever reading someone else’s C++ program and want to find where it starts, just look for the function named main .