Outline for Today

Creating a Project in Microsoft Visual Studio 2015

Below is a guide to creating your first project. This was taken from the PIC department website, then edited a little to fit our class. If you're interested, here is the original.

Microsoft Visual Studio is an environment which allows you to create, edit, save, debug, compile, and run C++ programs.

Projects Every C++ program is contained in its own project directory. Whenever you start a new homework assignment or any C++ program, you must create a project within Visual Studio first and add C++ source code files (text files with extension .cpp) to that project. In this guide, we will show you how.

Solutions A solution is a file that groups related C++ projects together in order to organize them. In this class we will likely create one solution file that contains all of our PIC10A projects.

To create your first project and solution for your homework, follow these steps:

Step 1

Open Microsoft Visual Studio by clicking the purple infinity icon visualStudioIcon. We will be using Microsoft Visual Studio 2015 in this class. (any version is fine. In particular, I recommend the Community version for your home computer. It's free.)

If this is the first time Visual Studio is opened on your computer, you should see a pop-up similar to the below image. Uncheck the checkbox. Select "Visual C++ Development Settings." Then press "Start Visual Studio."

If you don't see this pop-up, don't worry about it. Just go straight to step 2.


Step 2

Select "File," then "New Project."


Step 3

Under the "Installed" and "Templates" headings, click "Visual C++" and then "Win32 Console Application" in the middle frame. Type in the name of your project "HelloWorld" in the text field labeled "Name". Be sure to create the project on your personal "Z:" network drive by entering the location "Z:\Documents\Visual Studio 2015\Projects" in the text field labeled "Location." Then click "OK."


Step 4

The dialog below will appear. Click "Application Settings" and then select "Console Application," uncheck "Precompiled Header" and "SDL checks," and then check "Empty Project." Click the "Finish" button.


Step 5

Your solution "HelloWorld" and Project "HelloWorld" are displayed in the Solution Explorer. Right-click "Source files," select "Add", then "New Item" to create source code.


Step 6

Under Visual C++, select "Code." Then select "C++" File in the middle frame. Enter the name of your C++ source code file "HelloWorld.cpp" and press "Add." This will create the source code file (a plain text file) inside your HelloWorld Project folder and integrate it into your program.


Step 7

Type this C++ code into the source editor and press CTRL-S to save. Don't worry about what any of it means. We'll go over that later.


Step 8

After editing the source code file, select the "Build" menu and then "Build Solution" to compile your project. The compiler will translate your source code into a binary executable (.exe) file written in your machine's native language. The file "HelloWorld.exe" will be created as a result.


You will see the message "Build: 1 Succeeded" in the output window.


Step 9

To run program, select the Debug menu, followed by "Start without debugging."



Step 10

The output console will pop up and display the message "Hello World!"


(If you followed my instructions exactly, your final output won't have a space between "Hello World!" and "Press any key to continue...". I made a typo when setting this up, and now I'm too lazy to re-make the images)

Congratulations! You just completed your first C++ program! If you want to find the files associated to your project, look in the project folder "Z:\Documents\Visual Studio 2015\Projects"

Common Errors

If you finish early:

  1. Read this tutorial on the c++ webpage to get a short description of what your program is doing.
  2. Modify your Hello World program so that it prints exactly the following text (including spaces, new lines, quotes, etc.).
    "Uh, everything's under control. Situation normal."
    "What happened?"
    "Uh, we had a slight weapons malfunction, but uh... everything's perfectly all right now.
     We're fine. We're all fine here now, thank you. How are you?"
    • Some characters require special treatment to be printed to the screen. Try Googling "How to print quotation mark in c++" and "How to print new line in c++".
    • These special characters are called "escape sequences". Try googling that too!
  3. Errors: Try changing pieces of the code and see what happens when you build+run the program.
    • Take out one of the semicolons.
    • Take out the 'using namespace std;' line.
    • Take out the { or }, or include 2 copies of one or both.
    • Try at least one other adjustment!
    Many small changes will give an error during the build process. A big part of learning to fix your mistakes will be getting the hang of what the various error messages mean.
  4. Find your code in Windows Explorer: In step 3 above you chose your project directory. This is the place on your computer where all your code is stored. Navigate your way to this folder, and try to find your .cpp file.