Handout 1: How to Create, Compile, and Run (Execute) a C++ Program

 

  1. Click on "Start" located in most of the computers at the bottom left of your machine.
  2. Select "Programs".
  3. Select "Microsoft Visual Studio 6.0".
  4. Select "Microsoft Visual C++ 6.0".
  5. Visual C++ window will open together with a small window titled "Tip of the Day". Close the small window.
  6. Select "File" from the menu at the top.
  7. Select "New".
  8. A small window titled "New" will open. From its menu (at the top), select "Files".
  9. Select "C++ Source File".
  10. In the same window, you'll find an item titled "File name". Enter the name of the file there (with no extension; the computer will add the extension). For illustration, assume that you've chosen the name of the file to be "Prog1".

Note: The name of the file can consist of

  1. Below that, you'll find another item titled "Location". Under the word "Location", you may find something like "C:\WINNT\Profiles\fenton2164\Desktop"

The file will be stored in that location. If you want to store the file on a floppy disk or in a different directory than that specified, simply click on the small button (with the dots) located to the right of the name of the location, then choose the intended drive and directory.

  1. A window will open titled "Prog1.cpp". Every C++ source file will have the same

extension (I mean ". cpp").

  1. Now write your program in the open white window.
  2. To compile the program, select "Build" from the top menu of Visual C++ (which is titled Microsoft Visual C++).
  3. Select "Compile Prog1.cpp".
  4. A message box titled "Microsoft Visual C++" with contents "This build command requires an active project workspace. Would you like to create a default project workspace?". Click the "Yes" button.
  5. Look at the small window on the bottom, you'll find something like

"-------------- Configuration: Prog1-Win32 Debug ---------------"

Scroll down if you don't see the bottom of that window. If there are no compile-

time errors (errors occur during compilation of the program; i.e translating the

source file (the one you wrote) to an object file (machine code) and no warnings

The last statement should be "Prog1.obj - 0 error(s), 0 warning(s)". If there are

errors or warnings, then you'll find the number of those errors and/or warnings written in the same location.

  1. If there are errors, then you cannot execute (run) the program. You must correct the errors first. To find the errors, simply look at the window at the bottom (scroll up or down if needed). You'll find in that window a description of every error. When you double click on the description of an error, a small blue cursor will point to the line where the error is located in your prpgram.
  2. If there are no errors, go to top menu again and select "Build". Then select "Execute Prog1.exe". Or instead, you can just preass "Ctrl" and "F5" simultaneously.
  3. A small message window will open asking you a question. Click "Yes".
  4. The output of the program will show up on a black window. The output will be followed by the statement "Press any key to continue". When you press any key, that window showing the output will disappear.
  5. To create and run another program, you need first to get rid of the output window, then to select "File" from the top menu, then to select "Close Workspace". A small message window will open. Click "Yes". Then select "File" again from the top menu, then select "New", then repeat step 8 and all of the following steps.
  6. Comments usually appear green and reserved keywords usually appear blue.