Using Visual Studio for Newbies

Are you a new student starting out in CSS342? Are you utterly confused on how exactly one can write and compile C++ code on a Windows computer? I noticed that many students tend to have problems making the transition from the languages and methods they used in introductory programming classes (142/143 or 161/162) to C++ used in intermediate level CSS classes (342/343) so I created this quick start guide to clear up the confusion.

If this statement describes you, follow the quick guide below to get up to speed on the basics of C++ development in Windows and actually start working on your homework and labs!

If you're a Mac user, check out the counterpart to this guide: Creating A Program in Xcode.

Getting Started

First, you will need to get Visual Studio Community (VSC). Microsoft provides VSC for free through the Microsoft site.

Additionally, all campus machines have Visual Studio Community installed.

Because machines on campus are using VS Community you will need to use your email address to register the software the first time you use it. This is a profile based registration so other users on the same machine will have to register individually.

For some of the benefits of registering VSC under your account take a look at the MSDN Signing into Visual Studio page.

Creating a Project

  • Start Visual Studio
  • Create a New Project
  • Select Empty Project, do not use the other options as VS will add Windows specific code that will cause conflicts.
  • Name the project and click Save
  • The project will be created by default in the Visual Studio folder in your Documents folder.

Adding Files to the Project

Now you will need to add your .cpp and .h files to the project. For those of you who are coming over from Java, header files may be confusing to you since Java does not support forward declarations. To keep it simple, the header file simply contains the forward declarations of the classes in the .cpp file. This allows the .h file to be easily reused.

  • To add .h files, right click on the Header folder and click on add new file.
  • Similarly for .cpp files, right click on the Source folder and click on add new file.

Compiling and Debugging your Code

Now that you have added some code in your files, you can now compile and debug your program. To do this, simply click on the green triangle play button in the toolbar. This will start debugging your code. If there are any errors, the program will not compile and let you know of these error. If there are no error, the program will compile and run.

One annoyance that occurs in Visual Studio is that compiling and executing the program will often bring up and close out the display for the program that you compile. Students tend to add code like System(“puase”) or something similar. This is not recommended since it can interfere with compilation especially when the instructor tests your program on Linux. The better alternative to this would be to establish a breakpoint in the code by clicking on the left scrollbar where you want to stop your code.


Now you're ready to start creating programs in C++ on Visual Studio. Don't forget to test out your program in Linux with g++. Most programs that compile under Visual Studio should also compile under g++ in Linux but problems can arise if you start using Windows specific functions in your programs. Professor Zander has a good writeup on doing this but unfortunately it doesn't have all the pretty pictures. Note to self: Create guide on transferring files to Linux with screenshots.

Twisty Bit: Excluding Files from the Build

There are times (such as when compiling C++ template files) that you may want to have .cpp files in a project and yet not have the compiler attempt to compile them. Here's an overview of how to do this, courtesy of a CSS 501 student in Fall 2019 (John Wyman):

1. Right click the file in the Solution Explorer and then click on “Properties” at the bottom of the menu that pops up.

2. Next, you'll see “General” properties with “Excluded From Build” as one of the options. There's a dropdown button to the right. Click the dropdown and select “Yes.”

3. Click “Apply” or “OK”. When you go back to your solution explorer, you'll see your file has a little “do not enter” sign over it.


The best way to find something here is to use the search box in the upper right or the site index link below.

Mobile QR Link