QUESTION: How do I set breakpoints, set watches, and set through an executing program line-by-line? ANSWER: We will use the program DebugMessage.cpp as our example. Open Visual C++. 1. You begin by opening the file DebugMessage.cpp.Visual C++ will then display the file DebugMessage.cpp in the code window
2. Once the file DebugMessage.cpp is open, you build the program, as shown in the Visual C++ Build Tutorial: Select Build | Build Solution or Ctrl+Shift+B. 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 >> number;
4. Run DebugMessage.cpp in debug mode by choosing Debug | Start or F5.
5. Note that execution stops at the point where the breakpoint was set.
6. Set a watch on the variable "number" by typing "number" 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 moved to the next, non-comment line of code and that "number" in the Watch1 window has the value you typed in for your Magic Number (here 129).
8. Step to the next line using Debug | Step Over (or F10) and see the value of "number" change according to the calculation executed in the assignment statement. Watch the yellow arrow move through the code one line at a time.
9. At this point, the cout statement does do output. It is visible if you switch
to the console window. You do not get the "Press any key to continue." prompt. |