Handout 1: How to Create, Compile, and Run
(Execute) a C++ Program
- Click
on "Start" located in most of the computers at the bottom left of
your
machine.
- Select
"Programs".
- Select
"Microsoft Visual Studio 6.0".
- Select
"Microsoft Visual C++ 6.0".
- Visual
C++ window will open together with a small window titled "Tip of the
Day".
Close the small window.
- Select "File"
from the menu at the top.
- Select
"New".
- A
small window titled "New" will open. From its menu (at the top),
select
"Files".
- Select
"C++ Source File".
- In the same window, you'll find an
item
titled "File name". Enter the name of the file there (with no
extension;
the computer will add the extension). For illustration, assume that
you've
chosen the name of the file to be "Prog1".
Note: The name of the file can
consist
of
- Below
that, you'll find another item titled "Location". Under the word
"Location", you may find something like
"C:\WINNT\Profiles\fenton2164\Desktop"
The file will be stored in
that
location. If you want to store the file on a floppy disk or in a different
directory than that specified, simply click on the small button (with the
dots)
located to the right of the name of the location, then choose the intended drive and directory.
- A
window will open titled "Prog1.cpp". Every C++ source file will have
the
same
extension (I mean ". cpp").
- Now
write your program in the open white window.
- To
compile the program, select "Build" from the top menu of Visual C++
(which
is titled Microsoft Visual C++).
- Select
"Compile Prog1.cpp".
- A
message box titled "Microsoft Visual C++" with contents "This build
command requires an active project workspace. Would you like to
create a
default project workspace?". Click the "Yes" button.
- Look
at the small window on the bottom, you'll find something like
"-------------- Configuration: Prog1-Win32 Debug
---------------"
Scroll down if you don't see the bottom of that window.
If
there are no compile-
time errors (errors occur during compilation of the
program;
i.e translating the
source file (the one you wrote) to an object file
(machine
code) and no warnings
The last statement should
be "Prog1.obj - 0 error(s), 0 warning(s)". If there are
errors or warnings, then
you'll
find the number of those errors and/or warnings written in the same
location.
- If
there are errors, then you cannot execute (run) the program. You must
correct the errors first. To find the errors, simply look at the
window at
the bottom (scroll up or down if needed). You'll find in that window
a
description of every error. When you double click on the description
of an
error, a small blue cursor will point to the line where the error is
located in your prpgram.
- If
there are no errors, go to top menu again and select "Build". Then
select
"Execute Prog1.exe". Or instead, you can just preass "Ctrl" and "F5"
simultaneously.
- A
small message window will open asking you a question. Click
"Yes".
- The
output of the program will show up on a black window. The output will
be
followed by the statement "Press any key to continue". When you press
any
key, that window showing the output will disappear.
- To
create and run another program, you need first to get rid of the
output
window, then to select "File" from the top menu, then to select
"Close
Workspace". A small message window will open. Click "Yes". Then
select
"File" again from the top menu, then select "New", then repeat step 8
and
all of the following steps.
- Comments
usually appear green and reserved keywords usually appear blue.