//. h file#pragmaOnceclassCconsoledump { Public: ExplicitCconsoledump (LPCTSTR lpszwindowtitle =NULL); Virtual~cconsoledump (void); Public: BOOL DUMP (LPCTSTR lpszfmt, ...); BOOL ShowWindow (bool Bshowwindow); BOOL SetWindowText (LPCTSTR lpszwindowtitle=NULL); }; //. cpp Files#include"StdAfx.h"#include"ConsoleDump.h" #defineMax_buffer_size (10 * 1024)cconsoledump::cconsoledump (LPCTSTR lpszwindowtitle) {if(AllocConsole ()) {if(NULL! =lpszwindowtitle) {Setconsoletitle (lpszwindowtitle); }}} Cconsoledump::~cconsoledump (void) {freeconsole (); } bool Cconsoledump::showwindow (bool Bshowwindow) {return:: ShowWindow (Getconsolewindow (), Bshowwindow?sw_show:sw_hide); } BOOL SetWindowText (LPCTSTR lpszwindowtitle) {if(NULL! =lpszwindowtitle) { returnSetconsoletitle (Lpszwindowtitle); } returnTRUE; } BOOL Cconsoledump::D UMP (LPCTSTR lpszfmt, ...) {TCHAR Sztext[max_buffer_size]= {0}; Va_list arglist; Va_start (arglist, lpszfmt); _vstprintf_s (Sztext, _countof (Sztext), lpszfmt, arglist); Va_end (arglist); returnWriteconsole (GetStdHandle (Std_output_handle), Sztext, _tcslen (sztext), NULL, NULL); } //Test UsingCconsoledump M_dump;//A member variable defined as a class//where needed to use Cconsoledump::D UMP function output log information can beM_dump. DUMP (_t ("Hello, world!\r\n."));
This is just a simple package of several functions related to the console, for more console-related controls, you can refer to the MSDN documentation
Reference: http://blog.csdn.net/visualeleven/article/details/7628564
_CrtDumpMemoryLeaks memory leaks in the reporting program (simple sample Code)