Visual Studio .NET 2003 C++ Tutorial

This tutorial guides you through the process of creating a simple C++ console application using Visual Studio .NET 2003. (Based on a tutorial by Kevin Lillis at St Ambrose University)

Create A Project

First, create an empty folder somewhere convenient (Maybe in My Documents), and rename it something like 105_Projects.  You only need to do this once, at the beginning of the semester.

Next, start Microsoft Visual Studio .NET 2003 from the Start button, like this:

Start... Programs... Computer Science Programs... Microsoft Visual Studio .NET 2003...
    Microsoft Visual Studio .NET 2003

You will then see a Start Page.

Click the menu item File | New | Project... or press CTRL+SHIFT+N or click the New Project button.

A dialog box is displayed. (Figure 2) 

Click the OK button to continue.

Click Application Settings on the left side of the window and then place a check in the box marked Empty project. The screen should look like this:

Click Finish.

Typing the Source Code

Click the menu item Project | Add New Item... or press CTRL + SHIFT + A or click the Add New Item button.

Select C++ File (.cpp) from the list on the right and type the name squared in the text box labeled Name:, where it says <Enter Name>

Click Open. Enter the following program:

#include <iostream>
#include <string>

using namespace std;

void main() {
  string YourName;
  int x;
  int square;

  cout << "Please enter your name: ";
  cin >> YourName;

  cout << "Please Enter a whole number:";
  cin >> x;

  square = x * x;

  cout << endl;
  cout << "Hello, " << YourName << ", ";
  cout << "the square of " << x << " is " << square << endl;

Save your program by clicking on the icon that looks like a floppy disk (4th icon from the left).

Run Your Program

To run your program click the menu item Debug | Start Without Debugging or press CTRL + F5.

A dialog box will appear, saying the project is out-of-date, and asking if you would like to build.  Click the Yes button to compile your program.

If you receive any error messages recheck you program code and make sure it appears exactly as shown above. If your code has no errors it will compile and execute.

After your program runs, you can press any key to return to Visual Studio.  Note: every time to Compile & Run, your program gets saved for you.



Created by Matthew Weathers, August 2004