Microsoft Visual C++

Download and Install

Go to http://www.microsoft.com/express/vc/
>> Download Now!
Web Install
Microsoft Visual C++ 2010 Express Edition
English >> Download
You have chosen to open vcsetup.exe
You must restart your computer to complete the installation.

Type in the program and run it

FileNewProject…
In the New Project window, the left pane lists the project types and the right pane lists the available templates for that type.
Project types: General
Template: Empty Project
Name: prog
In the Empty Project Wizard window, press Finish.
ProjectAdd New Item…C++ File (.cpp)
Name: main.cpp
Press Add.
Now type in the file, stating with #include <iostream>. Don’t forget the system("PAUSE");.
FileSave main.cpp
DebugBuild Solution
DebugStart Without Debugging (or control-F5)
Press any key to continue…

Run the program from the command prompt

You can also run your executable from the Windows Command Prompt. Insert the statement

	system("PAUSE");
immediately before every return from the main function and immediately before every call to the functions exit or abort. Rebuild the executable. Then at the Windows Command Prompt (cmd.exe), go to the directory that holds the executable:
cd C:\Users\myname\My Documents\Visual Studio 2010\Projects\prog\Debug
dir
prog.exe
echo %errorlevel%

Turn off the Microsoft extensions

Projectprojname Properties…Configuration PropertiesC/C++LanguageDisable Language ExtensionsYes (/Za)
Press Apply and OK.

Compile and run Homework 1.7.3a (Chapter 1, p. 87)

A helpful student provided the following instructions.

  1. Create a Win32 Console Application. Create an empty project rather than use the precompiled header option which just puts some unneeded files and annoying code in the project. (The precompiled header option caused some grief concerning stdafx.h.)

  2. Then add new items to the project and copy your code into them. VC++ separates project files into three sections: Header Files, Resource Files and Source Files. Right click on those sections to choose
    Add → New Item…
    Create term.h in the header section and term.c and main.cpp in the source section. VC++ lists no code template for a C file, but if you choose the C++ file template and name the file with a .c extension, VC++ happily accepts it and does the right thing as explained below.

  3. At this point, having the three files in the project, compiled and run the program.

  4. Each file in a project has a ton of properties. One of the properties is “Compile As”. Right click on term.c to bring up its properties dialog and traverse the list:
    Configuration Properties → C/C++ → Advanced → Compile As,
    where you have the choices “Compile as C Code (/TC)” and “Compile as C++ Code (/TP)”. It had automatically chosen the C Code option when you named the file with a .c extension. You can test that by renaming the file to term.cpp; observer that the “Compile As” option changed to “C++ Code”. You could also change it manually.