COSC 236: Notes on Using Visual Studio

Course Home Page

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.

  1. Start Visual Studio
  2. Select "New Project" from the "File" menu. This will lead to a "New Project" dialog box.
  3. Select "Visual C++" from the list of project types on the list.
  4. Select "Win32 Console Application" from the list of templates on the right.
  5. 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.
  6. 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.
  7. 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.
  8. This will bring up the "Win32 Appliation Wizard" click Next.
  9. On the "Application Settings" select "Console Application" under "Application type", and "Empty Project" from "Additional options".
  10. Press "Finish"
  11. 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.
  12. 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
  13. Right click on source files, select "Add", and then "New Item" This will lead to the "Add New Item" dialog.
  14. Select "Code" from the categories list and "C++ File" from the templates list.
  15. Type the name of the file that you wish to create in the "Name" box. Generally, you will not edit the location field.
  16. Click the "Add" button. This will create the file and open it in the text editor pane on the right.
  17. Type in your program. Save it frequently using the "Save" from the "File" menu.
  18. 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.
  19. 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.