本人将网上两篇侧重点不同的文章组合起来形成了下面这篇文章。实践有效。
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_ 注释与否随便你 ^_^。