Using the Microsoft Visual C++ Compiler

  1. Start the Visual C++ compiler by clicking the Start/Programs/Visual C++ 2005 Express Edition command.
  2. Choose File/New/Project... from the menu. Click "Visual C++" on the left under Project types. Select "emptyproj" on the right under Templates. Type the name of the project under Name. You can use a name such as "a1" (i.e. assignment #1). This entry will end up being the name of a folder that is automatically created to store all of the files related to your new computer program. Click the Browse button to specify a location on your hard drive or USB flash drive for this folder (i.e. directory) or allow Visual C++ to store the folder in the default location of "My Documents\Visual Studio 2005\Projects". Make sure there is a checkmark next to "Create directory for solution". The Solution Name should be the same as the name that you specified above. Click the OK button.
  3. Click the Project/Add New Item... menu command.
  4. Select "Visual C++" under Categories on the left. Select "C++ File (.cpp)" under Templates on the right.
  5. Type the name of the source file (e.g. a1) for Name. It is simple and easy to remember if you type the same name for this C++ source file that you used for the project in step #1 above. It is optional to type the .cpp file extension. The location should be the folder that was specified and automatically created by step #1 above. Click the Add button.
  6. Type the source code for your program.
  7. Click the Build/Build Solution menu command. This compiles your program which checks it for errors. You must compile the program before executing it.
  8. Any errors in your program will now be indicated in a window at the bottom of the screen. If you do have any errors, scroll-up in the error window and double-click anywhere within the line that describes the first error. The compiler will probably highlight a line of your program where it believes an error is located. Sometimes this is a misleading since the error may be on a line before the highlighted line of code. Anyway, you should find and fix that error and try compiling your program again. Do not worry yet about fixing any other errors that you might see listed since they may be errors that resulted from the first one that you fixed. Also, you can generally disregard warnings since they do not prevent your program from executing and are sometimes incidental. The process of fixing errors in a program is called debugging.
  9. To run (i.e. execute) your program, click the Debug/Start Without Debugging menu command.
  10. When your program executes, it's output will be displayed in a black DOS console window. After you have studied the program's output, press any key to continue.
  11. To print your program's source code, click the File/Print... menu command.
  12. When you are finished writing, modifying, & recompiling your program, click the File/Exit menu command to completely exit the Visual C++ compiler. Your program (the .cpp source file) is now saved in the folder that was created in step #1 above. If you are planning to immediately write another C++ program, you should click the File/Close Solution menu command or completely exit the Visual C++ compiler software and follow these instructions from the very beginning.
  13. To copy your source and executable files to a USB flash drive or CD-ROM, copy the whole project folder to that new location. The source file is the file with the .cpp file extension. That is the most important part of the project since it will need to be printed out and possibly uploaded to Angel. The executable file with a .exe extension is also important and may need to be uploaded to Angel. Double-clicking the exe file will run your program even on Windows computers that do not have the Visual C++ compiler installed. You will find the .exe file in a folder named Debug. The .exe file extension may not appear as part of the file name depending on the settings on your personal computer but you can recognize this file by its rectangular icon. There will be many other files in the project folder that are relatively unimportant but that should not be deleted.

Modifying a program that you already have saved.

  1. Double-click the file with the .sln file extension. Click the File/Open/Project/Solution menu command and find and click the file with the sln file extension or the file with the vcproj file extension.
  2. If necessary, click the plus symbol next to the name of your project on the left. Then click the plus symbol next to "Source Files" on the left. Finally, double-click your .cpp source file in order to open it in the main editing window.