Simple Commandline Enabled Example

Top  Previous  Next

Here is a complete example that shows how easy it is to make an application that turns on debugging ONLY if the user passes the command line flag -dbc (for console output) or -dbf (for file output).  Call your app with -dbc to see debug output on console, and/or -dbf to write debugging info to file.  Add -dbb for briefmode output.

 

//---------------------------------------------------------------------------

// JrDebug simplest demo

//---------------------------------------------------------------------------

 

//---------------------------------------------------------------------------

// System includes for std::cout usage below

#include <iostream>

//---------------------------------------------------------------------------

 

//---------------------------------------------------------------------------

// Include the Debugging Library file (only our main should include this

//  file, additional .cpp files should include "jrdebug.h"

//  alternatively, you could add this cpp to your project or makefile.

#include "../../jrdebug_main.cpp"

//---------------------------------------------------------------------------

 

 

//---------------------------------------------------------------------------

int main(int argc, char *argv[])

{

 // automatically parse commandline options and exit if appropriate

 if (JrDebugParseCommandlineArgc("Demo1",&argc,argv,"-db"))

         return 0;

 

 // C++ iostreams style logging:

 debugout << "Main started with argc = "<<argc;

 // printf style logging:

 dbprintf("Main started with argc=%d",argc);

 

 // return success

 std::cout << "Program has finished; if you were running the debug monitor you should have seen 2 messages."<<std::endl;

 return 0;

}

//---------------------------------------------------------------------------