![]() |
Visual C++ Debug Tutorial |
QUESTION: How do I set breakpoints, set watches, and set through an executing program line-by-line? ANSWER: We will use the program guessage.cpp as our example. Note that we are using Visual C++ version 6. However, the steps in Visual C++ version 5 are very similar. Open Visual C++. 1. You begin by opening the file guessage.cpp as shown in the Visual C++ Build Tutorial.Visual C++ will then display the file guessage.cpp in the code window
2. Once the file guessage.cpp is open, you build an executable version of the program, as shown in the Visual C++ Build Tutorial: Select Build | Build. Visual C++ will ask if you want to create a default project workspace. Select Yes. 3. Set a breakpoint at the following line by clicking the cursor on this line, and then clicking on the "hand" (Insert/Remove Breakpoint). A red breakpoint "stopsign" appears to the left of the line of code. cin >> num;
4. Run guessage.cpp in debug mode by choosing Build | Start Debug | Go.
5. Note that execution stops at the point where the breakpoint was set.
6. Set a watch on the variable "num" by typing "num" in the name column of the Watch1 window in the middle of the screen.
7a. Step to the next line using Debug | Step Over (or F10).
7b. And enter your magic number and press Enter. 7c. You will see the yellow arrow (that marks the current line in the code) has move to the next, non-comment line of code and that "num" in the Watch1 window has the value you typed in for you Magic Number (here 129).
8a. Step to the next line using Debug | Step Over (or F10) and see the value of "num" change according to the calculation executed in the line of the program. Watch the yellow arrow move through the code one line at a time.
9/99 |