You are here

C++ Program Layout

5 February, 2015 - 11:20

From the above example, you can see that 2/3 of the program is the two functions. Most C++ programs have several items before the function main. As in the example, they often are:

  1. Documentation Most programs have a comment area at the start of the program with a variety of comments pertinent to the program. Any line starting with two slashes // is a comment and the compiler software disregards everything from the // to the end of the line.
  2. include<iostream> This line of code inserts a file into the source code. The file contains necessary code to be able to do simple input and output.
  3. using namespace std The C++ compiler has an area where it keeps the identifier names used in a program organized and it is called a namespace. There is a namespace created in conjunction with the iostream file called: std. This line informs the compiler to use the namespace std where the identifier names in the iostream are established.
  4. Function prototypes have already been explained.
  5. We need some variables (storage areas) for this program to work. They are defined next.