本人将网上两篇侧重点不同的文章组合起来形成了下面这篇文章。实践有效。
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_ 注释与否随便你 ^_^。
本文介绍了一种在MFC对话框应用中使用控制台进行调试的方法,通过在头文件中引入conio.h并定义宏来实现debug打印功能。文中详细展示了如何启用和禁用控制台输出,并给出了具体的代码示例。
1089

被折叠的 条评论
为什么被折叠?



