Professional Documents
Culture Documents
Visual Studio C++ Tutorial
Visual Studio C++ Tutorial
INTRODUCTION
Microsoft (MS) Visual C++ allows you to create many different types of applications written in
the C++ programming language. It is part of MS Visual Studio 2008, which allows software
developers to develop software applications in several programming languages including C++.
This guide addresses creating and using C++ Console Applications. A console application is a
computer program that enables a user to interact with a computer via a keyboard and display
screen. The application runs inside a DOS window. This guide is divided into the following
sections:
Starting Visual C++
Creating and Executing a Single-File Console Application
Importing and Executing C++ Source Code Files
Figure 1 shows the initial application window. If your application window looks different, you
may need to adjust the settings. You need to change to the Visual C++ Development Setting.
You can change the settings by clicking the Tools menu and selecting Import and Export
Settings. Select the Reset all settings option and click Next twice. Then, you will see a dialog
where you choose a default configuration as shown in Figure 2. Select Visual C++
Development Settings and press Finish. Finally, you will close the Reset Complete dialog
box. If this is the first time youve run Visual Studio, you will be shown the Choose Default
Environment Settings dialog similar to Figure 2. Select Visual C++ Development Settings
and press Start Visual Studio.
Remove checkmark
The application provides a default location for saving projects or you can select your own
location by pressing the Browse button to the right of the location textbox to open the Choose
Directory dialog box.
Press the OK button after entering the required information into the dialog box. When the
Win32 Application Wizard appears, click on Application Settings, select Console application
from the Application types and check Empty project (see Figure 4) and then press the Finish
button. The Solution Explorer now contains the information about your project (see Figure 5.)
Note how the Start Page now has your project listed. This will be a shortcut to starting the
project the next time you run Visual Studio.
Alternatively, you can right-click on the Source Files folder in the Solution Explorer (left hand
pane) and select Add, then New Item. (See Fig 7).
Both methods above bring up the Add New Item dialog shown in Figure 8. Expand the Visual
C++ option (press the + if not already done.) Select Code in the Categories pane and C++ File
(.cpp) in the Templates pane.
Enter a name for the file. The Location setting should be the same as your project, so no
change is needed in that field. Press the Add button to create the file.
CategoryType
The program results will appear in a new DOS window. Notice that the phrase Press any key
to continue has been added to the program output. This additional code was added to keep the
DOS window open until you have had a chance to view the output and press a key on the
keyboard. (See Figure 12.) Once a key on the keyboard is pressed, the program stops execution
and the DOS window closes. This output phrase is not actually included in your program, as
you would see if you opened a DOS window and executed the program directly.
Error pointer
Notice in this case that the pointer is on the line after the line containing the actual error. This
occurs when the error induces a compiler recognized fault on a subsequent line. While not
always exact, the error pointer, in conjunction with the error description, can help locate errors
in the source code. Once the error is identified and corrected, the program must be saved,
rebuilt, and executed again.
Summary
Microsoft Visual C++ allows you to create many different types of applications. This guide
addressed creating and using single source file Console Applications, but the basic operations
are the same for more complex programs.
Always start by creating a project file of the appropriate type
Create blank files for writing your own programs or import existing files into the project
Compile
Build
Execute
Debug, if necessary