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 2015 (VSC). Microsoft provides VSC for free through the Microsoft site or you can download it through the UWB CSS Dreamspark subscription (login required). If you have not received a registration email from DreamSpark please send an email to uwbstitl@uw.edu.

Additionally all campus machines have Visual Studio Community 2015 installed.

Because machines on campus are using VS Community you will need to use your @uw.edu 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 2010
  • 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 2010 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.

Success!

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.

Navigation

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

Print/export
Mobile QR Link