Unit #0 Introduction

Return to Unit

Using Visual C++ ( step by step)

Step 1:

From Start select Programs - Microsoft Visual Studio - Microsoft Visual C++

click for more
Step 2: Select a new C++ source file to write your program or open an old file click for more
Step 3: Type a few lines of your program in the editor window. click for more
Step 4: Save as the file in a temporary folder ( a folder on the desktop or in a location of C:) click for more
Step 5: Finish typing your program. Inspect it.
Step 6: From Build button select Compile. Watch the messages generated in the debug W. click for more
Step 7: Correct your syntax errors. Try to eliminate all warnings as well, if possible. click for more
Step 8: Once all compilation errors are fixed, from Build select ! Execute ( it will first Build) click for more
Step 9:

If there are no Build or Execution errors, a DOS screen will appear.
Inspect your results carefully.

click for more
Step 10: If you are going to work on another program and save it with a different name,you must select from File, Close Workspace. If you want to reuse some lines of the code you wrote ( typical) , answer No to the dialog question.

Step 1: From Start select Programs - Microsoft Visual Studio - Microsoft Visual C++

If you have done the installation of the Visual Studio correctly, then clicking on the Start button and subsequently on the Programs button should reveal the Microsoft Visual Studio 6.0 with its own selection buttons. Select the Microsoft Visual C++. When the program starts, it will open like this:

The dark gray space on the right upper side is the location where you will be writing your program, once you open a new file as described in Step 2. The editor window docks into this space.
The white window at the bottom is the place where the compiler messages and warnings are given.
The light gray window on the upper left is used to navigate files and workspaces in programs that consist of many files. In this course we will not be using this facility. So, you may as well close this window by clicking on the X.

(top)

Step 2Select a new C++ source file to write your program or open an old file

To open a new C++ source file, click File and select New. You will be shown the following selection window

Tab on Files and then select C++ Source File as shown below and click OK.

The picture below shows how the Visual C++ program looks at this point ( you remembered to close the workspace window on the upper left side). Notice the default name for the file Cpp2. We will change this in Step 4.

 Step 3: Type a few lines of your program in the editor window.

Here we show just a few lines of a very simple program. Notice that the editor ( knowing that we are writing a C++ source file) uses color to make our inspection of the text easier. Green is used for comments, blue for reserved words and the rest is black.

(top)

  Step 4: Save as the file in a temporary folder ( a folder on the desktop or in a location of C:)

We must now save our file in a location of our choice. It is suggested that you create a folder on the desktop, named it with your own Lehigh user ID ( mine is jyk0 ) and save your incomplete file there. This saving must be done often during our writing of the program so that we don't lose our work. Notice that we choose our own name for the file ( in this case example1 ). Here is the Save dialog:


(top)

Step 5: Finish typing your program. Inspect it.

Step 6: From Build button select Compile. Watch the messages generated in the debug W.

After completing our program, we saved it again and then from the Build button we selected Compile. Visual C++ responds with the question:

We answer Yes here, and then the software generates the following messages in the debug window:

There is one error: a missing ' ; ' . The line number is indicated as 12. Actually if you double click on the error statement a thick arrow will point to line 12. But the missing semicolon is actually at the end of line 10. This is very common. The compiler will often show the line after an error has occurred.

There is also a warning: Visual C++ is not happy when you write main . It prefers void main( ). At this point we cannot explain what void means. So we either agree to live with this warning ( it is OK) or we write void in front of the word main just to satisfy the compiler.

(top)

Step 7: Correct your syntax errors. Try to eliminate all warnings as well, if possible.

After correcting both of these, here is what we get ( if we recompile).

(top)

Step 8: Once all compilation errors are fixed, from Build select ! Execute ( it will first Build).

When the ! Execute button is pressed the following dialog may appear ( depending on what we might have done earlier, the dialog may look a bit different)

We answer Yes here and we get the following 2 screens: One of them indicates that the execution did not encountered any errors

The next one is a default black MSDOS window which contains our output. This secondary window disappears when any key is pressed.

Please note that in our programs we will have an additional "screen holding" device as illustrated in the examples of Unit1. We do this because the automatic screen hold of Visual C++ does not work when the executable is run independently from the editor.

(top)

Step 9: If there are no Build or Execution errors, a DOS screen will appear. Inspect your results carefully.

We cannot overemphasize here the importance of checking by hand ( actually by calculator) one or more of the numbers in the output of our programs. Many times there is a simple error which produces incorrect numbers. The program works, gives results that may look good but they may be wrong or imprecise. A check by hand as described above, very often reveals such errors.

(top)

Step 10:If you are going to work on another program and save it with a different name,you must select from File, Close Workspace. If you want to reuse some lines of the code you wrote ( typical) , answer No to the dialog question.

(top)

Jacob Y. Kazakia © 2001 All rights reserved