What Went Wrong?

This is one of the most feared problems a programmer must face. The program did something terribly wrong—so wrong that it behaved completely unexpectedly. How can you find out what happened?

In this case, you can use cout statements to find out where the program “died.” These statements provide a status report at the beginning of each step in the program. When a status report is not provided, you will know that the program stopped in the code just before that step.

To let these debugging statements show what is happening at each stage, the program will pause after each status report and require the user to enter a character.

Listing 4.3 shows the example with these debugging statements.

Listing 4.3. Example with Debugging Statements ...

Get SAMS Teach Yourself C++ in 10 Minutes SECOND EDITION now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.