本人將網上兩篇側重點不同的文章組合起來形成了下面這篇文章。實踐有效。
Taken from internet and used in internet !
1. 實例工程名爲Demo,在CDemoDlg.h中加入
#include<conio.h>
#define _DEBUG_
#ifdef _DEBUG_
#define debug(format,...) _cprintf("File: "__FILE__", Line: %05d: "format"\n", __LINE__,##__VA_ARGS__)
#else
#define debug(format,...)
#endif
2. 在CDemoDlg::OnInitDialog()函數中加入AllocConsole();
3. 示例:debug的用法與printf相同
Cstring str =Cstring(“xiaoming”);
debug(“hi,%s”,str);
4. 若需要關閉控制檯輸出,調用FreeConsole();
5. 發佈程序時,只要將AllocConsole();註釋掉即可。 #define _DEBUG_ 註釋與否隨便你 ^_^。