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. 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.
Introduction to Computers, the Internet and World Wide Web
Introduction to C++ Programming
Introduction to Classes and Objects
Control Statements: Part 1
Control Statements: Part 2
Functions and an Introduction to Recursion
Arrays and Vectors
Pointers and Pointer-Based Strings
Classes: A Deeper Look, Part 1
Classes: A Deeper Look, Part 2
Operator Overloading; String and Array Objects
Object-Oriented Programming: Inheritance
Object-Oriented Programming: Polymorphism
Templates
Stream Input/Output
Exception Handling
File Processing
Class string and String Stream Processing
Web Programming
Searching and Sorting
Data Structures
Bits, Characters, C-Strings and structs
Standard Template Library (STL)
Other Topics
Appendix A. Operator Precedence and Associativity Chart
Appendix B. ASCII Character Set
Appendix C. Fundamental Types
Appendix D. Number Systems
Appendix E. C Legacy Code Topics
Appendix F. Preprocessor
Appendix G. ATM Case Study Code
Appendix H. UML 2: Additional Diagram Types
Appendix I. C++ Internet and Web Resources
Appendix J. Introduction to XHTML
Appendix K. XHTML Special Characters
Appendix L. Using the Visual Studio .NET Debugger
Appendix M. Using the GNU C++ Debugger
Bibliography