Getting Started with Visual Studio and C++

by asperling on September 23, 2014

As we move into more advanced graphics topics, we will require you to write programs in C++. Luckily, you will not need to use any advanced language features (unless you want to) and all of the tools required are available for free. Everything you learned in CS 367 still applies. Java and C++ have many similarities, but also a few key differences.

The Tools

We will use Microsoft Visual Studio as our IDE for C++ programs. The latest version is Visual Studio 2013, and the CSL computers have version 2010 installed. I have not experienced any compatability issues between the two versions, but that does not mean they are not there.

Getting Visual Studio 2013 for free:

As a student, you have access to Microsoft’s Dreamspark program, which lets you download many different pieces of software for free (including full versions of Windows.)  Here’s how to get Visual Studio 2013:

Option 1:

Option 2:

  • From the Dreamspark student homepage, click “More Software Through Your School”
  • Search for “University of Wisconsin – Madison” and look for the Computer Science Dreamspark store
  • Enter your CS login and password to get access to the store.
  • Visual Studio 2013 should be listed under the “New” section of the store
  • From there you can download any version of Visual Studio 2013, including the Ultimate edition. The “Professional” version is just fine for our needs, and it is what the CSL uses.

Both of these options will download a Microsoft installer program used to actually download and install Visual Studio.

A Basic C++ Project

Once Visual Studio is installed, we can make new C++ projects (or “solutions” as Microsoft calls them.)

  • From the start page, click “New Project”
  • Select “Win32 Console Application” from the C++ menu. Make sure to check the “Empty Project” box so there is no unnecessary code added.
  • To add a new C++ source file, right click the Source Files folder, click add new item, and select C++ source.
  • From here you can code anything you want, but we’ll start with Hello World.
#include 

using namespace std;

int main(int argc, char * argv[]) {
    cout << "Hello World!" << endl;
    return 0;
}

Now we can run the code.

  • Clicking the little play button at the top will compile and run the project (or use the keyboard shortcut F5.) If all goes well, the console will appear and disappear right away.
  • In order to actually see your output, launch the program without debugging using the option from the “DEBUG” menu (or the keyboard shortcut Ctrl-F5).
  • If Ctrl-F5 does not work, you will have to change the project settings to explicitly make it a console application:
  • Right click the project and go to Properties.
  • Navigate to Configuration Properties -> Linker -> System
  • Set the SubSystem to “Console”

That’s all for now! If you have specific questions about C++, ask them on Piazza. We will add more advanced C++ tutorials soon.

Previous post:

Next post: