You are on page 1of 12

Collection: Sachin S.


Steps to compile and run a C++ Program

Compiler: Microsoft Visual C++ 6.0

Operating System: Windows

Step 1. Start the Microsoft Visual C++ programming environment by clicking Start,
Microsoft Visual Studio, and Microsoft Visual C++.

The following is the startup screen for the Visual C++ environment.

This window is the
editor window when
This window is the the editor is active.
'class' window when
working on a project.

This window is for messages from the

compiler/loader, especially error messages
for typographical errors.

The icon in the upper left under the File choice is pressed to obtain an editor window.

Click this icon to

obtain an editor
window to type in
your C++ program

When typing the C++ program source code no elements will be highlighted since the
editor treats the source code as a text file at this point.
If you wish the keyword highlighting to be activated you should explicitly save the file as
a .cpp file. See the explanation a few pages ahead.

Editor window. Type your
source code here.

After typing the C++ source code it should be saved as a .cpp file. The name should be
somewhat original. This does not include lab1.cpp, program1.cpp, or assignment.cpp.
The .cpp extension is necessary for the following steps to work correctly since the
compiler expects that extension for source files it should compile.

Use the File menu item.

Use the SaveAs option

to save the file

Source code for C++ program

(taken from "Problem
Solving with C++"

Choose a directory to save
the source file and other
files that Visual C++
creates for you.

After choosing the

directory and typing in a
program name, click on
Pick a representative
file name with the
.cpp extension

You now need to Build
the program to obtain an

Visual C++ requires the
program be part of a
'project workspace' and is
offering to create one for
Click on Yes.

Improperly spelled keyword
causes the error message
displayed below. It should be

The class window

in populated now
that a project is

Message window for Visual C++. The compiler

is complaining here about a misspelled
keyword. Use the editor to correct the typing

After making the correction you should build the executable.

Use the Build option on the menu to create
the executable. As you can see additional
menu choices are available now that the
program is part of a project.

For a successful build no errors should be found by
the compiler or the linker. You can now execute the

Under the Build menu is an
Execute option.

The program will execute in its own window. The
numbers for the number of pods and peas in the pod
were entered and the program printed the information.
To return to the Visual C++ environment press a key
and the execution window will disappear.