COSC 236: Notes on Using Visual Studio
These notes provide a basic introduction to using Visual Studio to
create, compile, and run C++ programs. These notes should apply to
Visual Studio Express as well.
In visual studio, a "solution" is a collection of one or
more "projects", each of which if a program that can be run
spearately. Each project is stored in a separate directory under the
main solution directory.
- Start Visual Studio
- Select "New Project" from the "File"
menu. This will lead to a "New Project" dialog box.
- Select "Visual C++" from the list of project types on
the list.
- Select "Win32 Console Application" from the list of
templates on the right.
- Type the name for your project in the "name" text entry
field. Note that this will be the name of the first program in the
solution that you are creating.
- Under solution name, type in a name - this will be the name for
the solution that contains various projects. One approach to this is
to have a solution for each lab assignment "lab 1",
"lab 2", etc. and projects for each problem in any given lab.
- Under location, choose an appropriate directory. You can try to do
this in a directory on your H: drive, but this has proven to be
unsuccessful at times. Alternatively, you can choose a directory under
c:\temp, and then copy the resulting files to your h:drive, flash
drive, or other location. Visual C++ project directories can be copied
and moved without any problems. Note that you are specifying a
directory to hold all of the directories for your solution, which will
be created by visual studio. Thus, if you want to create a solution named
"& in c:\temp, "c:\temp" will be the location that you
should specify.
- This will bring up the "Win32 Appliation Wizard" click
Next.
- On the "Application Settings" select "Console
Application" under "Application type", and
"Empty Project" from
"Additional options".
- Press "Finish"
-
- You will now be on the main visual studio page. On the left, you
should see a pane labeled "Solution Explorer", with the name
of the solution at the top, and the names of the projects
underneath.
Click on the name of the project that you want to work on You
will see folders for header files, resource files, and source
files
- Right click on source files, select "Add", and then
"New Item" This will lead to the "Add New Item"
dialog.
- Select "Code" from the categories list and "C++
File" from the templates list.
- Type the name of the file that you wish to create in the
"Name" box. Generally, you will not edit the location
field.
- Click the "Add" button. This will create the file and
open it in the text editor pane on the right.
- Type in your program. Save it frequently using the
"Save" from the "File" menu.
- When your code is typed in, select "Build Solution" from
the "Build" menu (or just hit F7). Compiler errors will be
displayed in the "Output" pane at the bottom of the
window.
- Once the program compiles correctly, you can run it by selecting
"Start without Debugging" from the "Debug" menu,
or simply type CTRL + F5.
To add new projects to a solution, right click on the solution
name, select "Add" and then "New
Project". Subsequent steps work as above, but you will not be
able to choose a solution name.
If you have multiple projects in a solution, you must choose the
appropriate project before you run it. To do this, right-click on the
project name and select "Set as StartUp project".
Please send me email if
you find any questions or problems with these notes.