Showing posts from March, 2013

Verbose Mode C++

Here is a quick tip for debugging a section of a C++ application. Often times, when you are in need of a quick way to debug a part of your code and do not want to go through the whole program and digest each line of code, you can use #directive. Below is an example of using this "verbose" directive:

#ifdef DEBUGMEM#define _CRTDBG_MAP_ALLOC#include <stdlib.h>#include <crtdbg.h>#endif#include <iostream> usingnamespace std; voidtest() { // Do something } voidmain() { test(); #ifdef DEBUGMEM _CrtDumpMemoryLeaks(); #endif }
When you put #define DEBUGMEM at the beginning of your code, the code inside the #ifdef and #endif will automatically be executed. This enables you to easily disable or enable each part of your code if needed. 

In this particular code, the _CrtDumpMemoryLeaks(); and its corresponding headers will only be included and executed when #define DEBUGMEM is pr…