Debugging legacy C++ in Visual Studio’s output window

Sometimes you are knees deep in legacy code and need to know what is going on. Sensibly you try to debug and step through. However, seconds later Visual Studio has started to crawl and it looks like you are stepping over at one line per minute.

At this point, consider logging to console instead of continuing to debug. In many cases this can be a vanilla printf but sometimes a printf is dropped by the application and nothing is logged.

In cases where printf produces nothing, you can use the Visual Studio debug output window to get some idea of the state of the system:

// sprintf into a character pointer (128 bytes on the heap) and output ASCII
char *str = new char[128];
sprintf(str, "%d %d\r\n", arrayIndex, arrayValue);