www.gibmonks.com

Main Page




Previous Page
Next Page

[Page 1377 (continued)]

L.5. The Autos Window

In this section, we present the Autos window, which displays the variables used in the previous statement executed and the next command to execute. The Autos window allows you to focus on variables that were just used, and those that will be used and modified in the next statement.

1.
Setting breakpoints. Set breakpoints at lines 14 and 22 by clicking in the margin indicator bar (Fig. L.27).

Figure L.27. Setting breakpoints in the program.


2.
Using the Autos window. Start the debugger by selecting Debug > Start. When execution halts at the breakpoint at line 14, open the Autos window (Fig. L.28) by selecting Debug > Windows > Autos. The Autos window allows you to view the contents of the variables used in the last statement that was executed. This allows you to verify that the previous statement executed correctly. The Autos window also lists the values in the next statement to be executed. Notice that the Autos window lists the account1 variable, its value and its type. Viewing the values stored in an object lets you verify that your program is manipulating these variables correctly. Notice that account1 contains a large negative value. This value, which may be different each time the program executes, is account1's uninitialized value. This unpredictable (and often undesirable) value demonstrates why it is important to initialize all C++ variables before use.

Figure L.28. Autos window displaying the state of account1 object.
(This item is displayed on page 1378 in the print version)


3.
Using the Step Over command. Select Debug > Step Over to execute line 14. The Autos window (Fig. L.29) updates the value of account1 after it is initialized. The value of account1 is displayed in red to indicate that it changed.

Figure L.29. Autos window displaying the state of account1 object after initialization.
(This item is displayed on page 1378 in the print version)


4.
Continuing execution. Select Debug > Continue. Program execution will stop at the second breakpoint, set at line 22. The Autos window (Fig. L.30) displays uninitialized local variable withdrawalAmount, which has a large negative value.


[Page 1378]


Figure L.30. Autos window displaying local variable withdrawalAmount.


5.
Entering data. Select Debug > Step Over to execute line 22. At the program's input prompt, enter a value for the withdrawal amount. The Autos window (Fig. L.29) will update the value of local variable withdrawalAmount with the value you entered. [Note: The first line of the Autos window contains the istream object (cin) you used to input data.]

6.
Stopping the debugger. Select Debug > Stop Debugging to end the debugging session. Remove all remaining breakpoints.

In this section, you learned about the Autos window, which allows you to view the variables used in the most recent command.


Previous Page
Next Page