Here’s a quick tutorial on how to create a project in the Microsoft Visual
C++ V6 Interactive Development Environment (IDE).
a New Project
Let’s say you’re starting out to work on the first assignment for the
course. It makes sense to create a project for this purpose. So
let’s see how we can create a project to satisfy our needs.
Microsoft Visual C++ on your PC (it should be available on all college
PCs). After it has shown a “splash screen”, you should then see
something like the following:
will probably be larger; I’ve reduced the size of the window to make the images
in this web page more reasonable to view.)
Now, click on the File->New… menu
that this is not equivalent to clicking on the leftmost toolbar, which looks
like it does that same thing. It does not do the same thing, as its tooltip “New
Text File” indicates.
This will bring up a dialog that looks as follows:
You must select
Win32 Console Application, as
shown above. This is very important: if you choose any other option,
you will probably spend hours trying to figure out lots of irrelevant things
about Windows applications. We are not creating Windows-specific
applications in this course.
Then you need to specify where all the files for your project will be
located. To do this, click on the small button to the right of the
text field, and navigate to a suitable directory below which your project
directory will be placed. If you are using your own PC, you can
probably take the default that is already set up. However, on a college
PC, you will need to ensure that the location is somewhere on your P: drive —
Finally, enter a name under the
label. For assignment 1, this might be
Once you’ve completed all of the above, click on the OK button, and you
should see the following:
recommendation is to accept the
An empty project
option, and click on Finish, which will bring up yet another dialog like this:
that I chose the project name
Assignment1, and I
placed in the default location on my home machine, as shown above, under
Finally, click on OK, and you should see the
following in your main Visual C++ window:
where you can see that something new has been introduced for Assignment1, on
the left-hand side. This is called the Workspace.
Now, click on the FileView tab in the
workspace (the tabs are at the bottom), and expand
Assignment1, and you’ll see something like:
As you can see, there are no source files present, because we created an
Before continuing, I strongly recommend the following:
- Click on the Project->Settings… menu item:
which will bring up the following dialog:
- Now, click on the C/C++ tab, and you should see the following:
- Click on
Precompiled Headersin the
pull-down list, as show above, and it should display the following:
- Now, click on the radio button
Not using precompiled headers.
This will save you time trying to figure out things like “What’s this
stdafx.h header file, anyway?” In other words, it will allow you
to focus on learning C++, and avoid having to learn the quirks of Visual
You can now exit the dialog, and your project settings should be set up for
The last part of the AST assignment will require a small tweak to your
project settings. Here’s what you have to do.
- First, go into the Project Settings dialog, as shown in the previous section.
- Click on the
C/C++tab, and choose
C++ Languagein the
list. You should now see the following:
- Click on the
Enable Run-Time Type Information (RTTI)
checkbox to set it, and then click on OK to return to the main Visual C++
Populating your Project, Editing, Compiling, Linking & Running your
So let’s add a source file to the project. Note the following:
- There are two kinds of source files we’ll be dealing with:
- Header files, which have a
- Regular source files, which (for C++) have a
filetype. For C, they have a
filetype. The distinction is important, because it will control
how the compiler interprets the source.
files to a project’s source files.
You do not add
.h files to a project’s
source files. They will normally get added (under Header Files), once your
have been compiled, and seen to depend on those header files.
So let’s add a new C++ source file. There are probably a number of
different ways to do this, but here’s one convenient way:
- Click on the
New Text Filetoolbar icon (the
leftmost icon in the toolbar) in the upper left of the Visual C++ window.
This will produce something like the following:
where the only visible changes are that the window’s title bar now shows –
(your name may be different), and the right hand side is now white. You
will also notice that there is a text cursor in the upper left of this newly
white area, indicating that you can how type into this area.
- A convenient thing you can do at this stage is to right click in the newly
white area, and select
pop-up menu, which will bring up a dialog like this:
Here, you can select the language, tab size, and indent size. My
The reasons for these suggestions are:
- When Visual C++ knows that the source is C/C++, it can use that
information to provide a lot of added value, including syntax
coloration, automatic formatting features, etc.
- A tab and indent size of 2 is economical in terms of horizontal space,
and the Visual C++ editor will automatically use these values for its
Finally, click on the
xin the upper right corner of
the dialog. This will dismiss the dialog, and you can start
- Now, you can start typing into the white area. I typed in a
“Hello World!” C/C++ program, and it looked like the following:
Notice the syntax coloration, and the indentation, which the editor did for me
automatically. Notice also that the titlebar shows an asterisk:
This means that the file has been changed, but not yet saved.
- OK, so let’s see if it compiles!
First, we have to save the file, so click on the Save toolbar icon (the one
that looks like a floppy disk). That will cause you to see a dialog:
As you can see, Visual C++ has given it a name of
The name that Visual C++ provides is rarely useful. Change the name to
something more appropriate, such as
and click on Save.
In the Visual C++ window, look to the right of the second toolbar (the one
etc.) , and you should see some icons that control compilation, building and
running of the program. These icons live inside a dockable toolbar, so
I’ve undocked it to show what they look like; see the
Because the hello.cpp is saved, and is currently selected in the edit
window, the left-hand icon in the Build Minibar is enabled. Click on it,
and you will see:
Click on Yes, and you should see a number of things happen:
Note that there is now an entry under
in the workspace, and that the
Buildtab of the
area at the bottom of the main window shows that
was compiled (successfully).
- So far, so good. How about linking it?
The second icon in the Build Minibar is the one to use now. Its
tooltip says “Build”, but I tend to think of it as the link stage,
whose end result is a runnable program. Clicking on this icon, gives
us the following:
The only visible change is that the Build tab now says that we have
successfully linked the program.
- So, now we can run it, right?
Yes, but if you do, it’ll probably run, and then disappear so fast that you
won’t have a chance to see what it did.
Instead, let’s run it under the control of the debugger. One of the
most useful things the debugger can do for you is to specify breakpoints
in your program. Breakpoints are locations where, when the program is
running under the control of the debugger, it will be told to stop.
So let’s set a breakpoint. Right-click on the gray area to the left
statement in your above editor window. The resulting menu will look like
If you click on the Insert/Remove Breakpoint item, you will see the
- There is now a dark red dot to the left of that statement, which
indicates that the debugger has placed a breakpoint at that point.
(I chose this location so that I could catch the program before it exits.)
- I am also showing another taskbar — the Debug taskbar, which I can use
to control the running of the program. (Right click in a clear
section of the taskbar area, and you will see a popup menu with which you
can enable this taskbar.)
So let’s run the program under the debugger:
- Click on the icon in the Build Minibar that is the second icon from the
right. (Its tooltip says
) this will start the program under the debugger, and after a short
delay, you will see something like the following:
There is now a yellow arrow superimposed on the dark red dot, which
indicates that the debugger has stopped the program at this breakpoint.
There are also two windows at the bottom of the Visual C++ main window:
One indicating a Debug tab, and the other with aother dark red dot with
superimposed yellow arrow. The latter is a call stack display. If
the program had been more complex/realistic, this would show what function you
are currentlly stopped in, and also how you got there.
There is also one more thing:
A Windows console, showing the output of the program.
- How about continuing the program, or stepping it from statement to
statement, all under the control of the debugger?
That’s what the Debug taskbar is all about. Among others, there are
- Restarting the program
- Stopping debugging the program
- Step Into
- Step Over
- Step Out
- Control the display of the various debugger-related windows.
So, in our situation, to stop the program at this point, we can choose to
- Click on the Debug taskbar icon to stop debugging, which will
terminate the program immediately
- Click again on the Build Minibar taskbar icon
which will cause the program to continue running under the
debugger. In our case, there is nothing of significance for the
program to do, besides simply exit normally.
More Ways to Add Source Files to a Project
There are a couple of other ways to add source files to a project:
- Right click on the Source Files entry in the Workspace, and from the
resulting menu select the
Add Files to Folder...
- Click on the
Project->Add To Project->New...
This will bring up a dialog box like:
which, of course, gives you much more flexibility. Most of that
flexibility is for Windows application development, not developing simple,
straightforward C++ programs. So you can ignore most of the above
For this course, you will only need to add one or more
Even though you can add a
C/C++ Header File,
you won’t need to do that explicitly for this course.
Note: Although you can (and in most non-trivial cases, should)
have multiple C/C++ source files in a project, you can only have a single main
entry point. If you try to have multiple sources, with more than a
single main entry point, you will get errors at the link stage.
I have a couple of observations regarding this:
- You can create a single project for each main entry point you wish to
use. However, this tends to be like cracking a walnut with a
sledgehammer, especially for simple programs.
- You can dynamically add and remove sources from a single project,
retaining only a single source with a main entry point. I find this
very useful for simple projects, especially relatively transient ones.
This page was last changed on 16 Jan 2006