Guide to Using the Visual C++ Debugger

1. Write your program, and make sure it compiles

2. Set a breakpoint in your code. Do this by clicking the cursor on the line that you want to set the breakpoint and then press the "set breakpoint" button. (You can also set a breakpoint using the right mouse button)



You may want to set the breakpoint at an early place in your code so that you can step through the whole program, or there may be a specific place where you want to start stepping through your program.

Note that it is possible to choose a line of code where Visual C++ can not stop. If this is the case it will automatically be moved down to the next valid line of code. (One place where Visual C++ does not seem to be able to stop is a declaration where you do not initialize the variable)

3. Now under the build menu choose "Rebuild All". This is necessary to force Visual C++ to recompile your code and add debugging information.

4. Now click the "go" button. The program will run until your first breakpoint.

Now that you've started the debugger what can you do?


The "step over" button allows you to execute the statement that the arrow is pointing at

The "step into" button executes the "sub-steps" that the statement the arrow is pointing at represents. If you are pointing at a function call, you will enter the function. This can be very confusing if you are pointing at a cin command and you go into the code for cin. To get back out of the function, push the "step out" button.

The "step out" button completes the running of the function you are in and takes you back to the next line of code after the function call

The "restart" button will start running your code again from the beginning

The "run to cursor" button runs your program up to the line where the cursor is flashing

The "stop debugging" button stops the debugger and puts you back into editing mode

The "quick watch" button allows you to check the value of a variable.

You can also force the system to let you watch the value of a variable as it changes by clicking under the word "name" in the bottom right hand corner of the screen and entering a variable name

Removing a program from your project


When you want to write a new program, you must first remove the old one from the project

Click on the File View Tab

(It may just have a picture of

a piece of paper)

First:

Click once on the + sign next to

Next:

CSandPTextProject files

Removing a program from your project Page 2 of 3

Click once on the + next to

Source Files

Removing a program from your project Page 3 of 3

Click once on the name of your

current program (to highlight

it) and then push the delete

key

This DOES NOT delete your

program, it simply removes

it from the project

At this point you may click

on the X to close the window

showing you your program

file. (Be sure your program

file has been saved before

doing so!) (You can save the

program by clicking on the

program window and then

selecting File -> save

Compiling and Running Your Visual C++ 6.0 Project


Compiling and linking your project:

. Click on Build/Rebuild All

If it compiles and links

successfully, the window at the

bottom of your screen will

display 0 error(s), 0

warning(s)

Compiling & Running your VC6.0 Project Page 2 of 3

To run your program:

Click on Build/Execute HelloWorld.exe.

The following output window should be displayed. When I press any key, the

window will be taken down and the program will stop.

Saving the project:

Click on File/Save All.

Closing the project:

Click on File/Close Workspace.

Compiling & Running your VC6.0 Project Page 3 of 3

What if I have compiler errors?

If you have compiler errors, click the mouse in the window at the bottom of your screen.

If necessary scroll to the top of this window to see your first error message. Click on the

error message. It will be highlighted. Double Click on the message. The statement

corresponding to the error message will be preceded by a blue arrow in the coding

window. In this case I simply typed ct instead of cout. Return to the coding window and

correct the error. Recompile the program.

Creating a new program in an existing visual C++ project


We now want to code the C++ program. To do this we have to create a new file.

Choose File/New

Creating a new program in an existing visual C++ project Page 2 of 2

When you are finished writing your

code, choose: File/Save.

Choose C++ Source

File

Be sure the project

name is the name of

the current project.

Enter the name of

your source file

(HelloWorld.cpp)

Be sure the saving

location is correct

Click on OK

Enter your C++ source

code into this window.