Using the Microsoft Visual C++ Compiler

  1. Make sure that your computer and monitor are turned on.
  2. Log on to the computer.
  3. If you are using a computer in the Penn State computer lab, open Windows Explorer by clicking the Start/Programs/Accessories command and verify that the C:\Temp folder is empty.
  4. Start the Visual C++ compiler by clicking the Start/Programming Software/Microsoft Visual Studio 6.0/Microsoft Visual C++ 6.0 command. Do not be alarmed if you see that the program MS Developer Studio 97 starts. Visual C++ is part of the Developer Studio suite (similar to how MS Word is part of the MS Office suite).
  5. Choose File/New... from the menu. Click the "Files" tab. Select "C++ Source File". Type the name that you wish to use for your program in the File name text box. I recommend that you do not use any spaces in the file name and that you end the file name with the extension .cpp. Then click the Build button (with three little dots) next to the Location text box and choose a location for your file. If you are working on a computer in the Penn State computer lab, you must choose the C:\Temp folder. (Of course, you could simply type "C:\TEMP" in the Location text box.) If you are using your own computer, you may store the program anywhere such as your My Documents folder. Click OK to continue.
  6. Type the source code for your program.
  7. Click the Build/Compile... menu command. This compiles your program which checks it for errors.
  8. Click "Yes" if you are asked if you wish to create a new workspace.
  9. Click "Yes" if you are asked if you wish to save any changes.
  10. 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 though this is a bit 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 fix the other errors that you might see listed since they may really 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 sometimes are incidental. The process of fixing errors in a program is called debugging.
  11. To run (i.e. execute) your program, click the Build/Execute... menu command.
  12. Click "Yes" if asked if you want to build an .exe file.
  13. 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.
  14. When you are finished writing, modifying, & recompiling your program, click the File/Exit menu command to exit the Visual C++ compiler. Your program (the .cpp file) is now saved in the C:\Temp folder along with some other files.
  15. If you are using a computer in the Penn State computer lab, insert your floppy disk and copy just the .cpp source file from the the Temp folder to your floppy disk. There will be many other files that are unnecessary and do not need to be saved. I recommend that you copy the .cpp source file with Windows Explorer under the Start/Programs/Accessories command. Do not use the File/Save As... menu command. Also, be aware that all files stored in the C:\Temp folder are automatically deleted when you log off a computer in any Penn State computer lab.

    Modifying a program that you already have saved.
  1. Until you really understand how the compiler works, I recommend that all students completely exit the Visual C++ compiler every time that they wish to begin a new program. Do not simply use the File/New... menu command to begin a new program within Visual C++ as if you were working on a second Word document in MS Word. Otherwise, you may see linking and other kinds of errors that you probably will not be able to fix.
  2. If you are working on your home computer and you would like to continue working on a program that you previously saved, you can probably double-click on the .cpp source file. This will usually cause the Visual C++ compiler to launch and bring up your program for editing. When you need to compile the program (i.e. check for errors) use the Build/Compile... menu command and answer "Yes" to any questions that appear. If the Visual C++ compiler does not automatically open when you double-click the file, you should open the program using the File/Open... menu command after first launching the Visual C++ compiler from the Start menu.
  3. If you are working on a computer in the Penn State computer lab and you would like to continue working on a program that you previously saved, you must first copy the .cpp source file from your floppy disk to the C:\Temp folder. Then double-click on the .cpp source file. This will usually cause the Visual C++ compiler to open and bring up your program for editing. When you need to compile the program (i.e. check for errors) use the Build/Compile... menu command and answer "Yes" to any questions that appear. If the Visual C++ compiler does not automatically open when you double-click the file, you should open the program using the File/Open... menu command after first launching the Visual C++ compiler from the Start menu.
  4. Don't forget to copy the final version of your program back to your floppy disk if working in the Penn State computer lab. Also beware! If you try to open a program straight off the floppy disk without first copying it to the C:\Temp, you will probably crash the computer since there is not enough space on a floppy disk for the automatically generated auxiliary files that the compiler creates along with the .cpp source file.

Practice Assignments #1 & 2:

  1. Follow the instructions above to create your first C++ source file named "practiceassignment1.cpp" and execute that file. Type the code below when necessary. Be sure to type the code exactly as it appears. C++ is very case-sensitive.

    // [Type your name here, without the brackets]
    // CMPSC 101
    // practiceassignment1.cpp
    // [Type today's date here, without the brackets]
    // Purpose - This program displays a hello world message.

    #include <iostream.h>

    int main()
    {
          cout << "hello world" << endl;

          return 0;
    }// end of main

    Compile and execute the program to make sure that it works before continuing with the next exercise. Printout the source file by choosing File/Print... from the menu.

  2. Use the File/Exit menu command to completely exit from Visual C++ (Developer Studio). Create another new source file named "practiceassignment2.cpp" following the compiler instructions above. Use Copy and Paste to transfer the code from http://www.minich.com/education/psu/cplusplus/week2lxr/FromWeb.htm to your new source file. Note that the character between the 2 and the x is the letter l (as in Larry) not the digit 1. Type your name and today's date where appropriate. Compile and execute the program to make sure that it works. If necessary, debug the program. Print out the source file by choosing File/Print... from the menu.

  3. Use Windows Explorer (not the File/Save As... menu command) to copy both source files, practiceassignment1.cpp & practiceassignment2.cpp, to the floppy disk that you plan to use to store all of your working files in this course. Also, copy both files to your backup floppy disk. Then copy both files to another blank floppy disk. On the floppy disk label write your name, CMPSC 101, the instructor's name (Mr. Minich), practiceassignment1.cpp, and practiceassignment2.cpp. No other files or folders should be stored on this floppy disk. Submit this floppy disk along with the stapled printouts (practiceassignment1.cpp on top) by the due date.