Console Applications in Visual C++ 2008
These are the directions to create a console (or text or DOS) mode
application in
Visual C++ 2008. These directions will work for your single file or multi-file
applications in CSIT
802, 832, 836, 839 and 840. These directions will not work for CSIT 861 because in
that class you will be creating Windows applications.
Glossary
These steps use some terminology you may not have heard before:
-
Application - A synonym for a
program. Word, Excel, Internet Explorer and Doom all are
applications.
-
Extension - The part of the
file name after the period. For example, if you name a file
teacherhavemercy.doc, the file extension is doc. The file
extension usually indicates the application you use to open the
file. For example, a doc file usually is opened in Word, an
xls file in Excel, etc.
-
Source file - This is a file in
which you write C++ code. It has a .cpp extension, which
stands for C++.
-
Header file - This is another
file that contains C++ code. It has a .h extension, which
stands for header. Some header files already are written for you.
Others you may write in advanced classes such as CSIT 832, 836
and 840; you likely won't in CSIT 802.
-
Project - A container for the
source and header files you write.
- Solution - A container for one or more projects. In our
classes the solution almost always will contain only one project.
When so, there is no practical difference difference between a
solution and a project.
Steps
OK, enough terminology! Let's get started creating a project
-
Choose the File > New > Project
menu command. This displays the New Project dialog shown in
Figure 1. (Ignore the values in the
Name, Location and Solution fields; they will be set in steps 4 and 5.)

Figure 1 - New Project dialog
-
Choose Visual C++ from the
list of Project Types, and then the Win32 subfolder.
-
Choose Win32 Console Project from the list of
templates. WARNING:
Do not choose the similarly named Win32
Project. If you do, you'll have to start all over.
-
In Location, using the Browse button,
choose an existing folder under which you will create the subfolder
in which you will put your project.
-
In Name, type the name you
choose for your project. This name also will be the Solution Name, and the name of the subfolder created to store your
project files. Hint: Choose a logical name, such as 839A1
for the first assignment in CSIT 839.
-
Click the OK button. This will display
the Win32 Application Wizard shown in Figure 2.

Figure 2 - Win32 Application Wizard
-
Don't
click Finish. If you do you may have to
start over. Instead, click Application Settings on the
left. The appearance of the Win32 Application Wizard then
changes to that shown in Figure 3.

Figure 3 - Win32 Application Wizard after choosing Application Settings
-
Make sure
under Application Type you choose Console
Application (that choice may already be the default).
Additionally,
under
Additional options, uncheck
Precompiled Header and check Empty Project. WARNING:
These are not the defaults
under
Additional options. Skipping
this step
is a common mistake and may require you to start over.
-
Click the Finish button. Figure 4
shows the new subfolder test and its parent
folder A1. (These were the name and location I chose in
Steps 4 and 5.)

Figure 4 - Windows Explorer showing newly created subfolder and files
-
Choose the View >
Solution
Explorer menu command to display Solution Explorer, which is
shown in Figure 5.

Figure 5 - Solution Explorer
-
So far the project is empty. To add a source (*.cpp) file,
choose the Project > Add New Item
menu command.
This will display the Add New Item dialog shown in Figure 6. You
also can display the Add New Item dialog by right-clicking
Source Files in Solution Explorer to display the shortcut menu shown
in Figure 7, and then choosing Add > Add New Item
from the shortcut menu.

Figure 6- Add New Item dialog (Default View)

Figure 7 - Shortcut Menu for Source Files
-
Choose Code from Categories
on the left. The Visual Studio installed templates on the
right will change to those shown in Figure 8.

Figure 8- Add New Item dialog after choosing Code in Categories
-
Choose C++ File (.cpp). Generally you will not
change the Location, which is the subfolder in which
the project files are stored. Type the name of the new
.cpp file in the Name box. I chose genghis.cpp. Then click
the Add button. Figure 9 shows the new genghis.cpp
file in Solution Explorer.

Figure 9 - Solution Explorer showing new .cpp file
In advanced classes, you may need to add additional .cpp
files, or h files.
You add additional .cpp files following steps 11-13. You would add .h files the same way except that in step 11 you would
right-click Header Files in Solution Explorer and in Step 13 you
would choose Header File (.h) instead of C++ File (.cpp).
Sometimes you may want to remove a file
from your project, though not from your hard drive. If so, right-click
that file and choose Exclude from Project from the shortcut menu. This does not remove the file from your hard drive.
Choosing Remove will delete the file from your hard drive.
Once your project contains the desired
files, then compile all of your project files at once from the Build
menu. Build is an incremental compile, Rebuild starts over. It doesn't
matter if you build or rebuild the project or the solution, since our
solutions only contain one project.
After compiling, run your project from the
Debug menu, either with or without debugging.