如果程序在调试时,输出窗口看不到了怎么办,那就让调试信息显示在命令行窗口
在InitInstance()中添加就能生成一个console.
#ifdef _DEBUG
if (!AllocConsole())
AfxMessageBox("Failed to create the console!", MB_ICONEXCLAMATION);
#endif
当然,必须在程序结束时进行收尾,在ExitInstance()中添加:
#ifdef _DEBUG
if (!FreeConsole())
AfxMessageBox("Could not free the console!");
#endif
在程序中需要输出调试信息的地方,可以运用这个调试窗口了:
_cprintf("Local value is %d\n", m_variable);
_cprintf的用法同printf一样。当然,要使用它,必须包含conio.h
#include <conio.h>
OK! That's all!
本文介绍了一种在调试过程中将调试信息显示在命令行窗口的方法。通过在程序的InitInstance()函数中调用AllocConsole()创建控制台,并在ExitInstance()中调用FreeConsole()释放资源。此外,还介绍了如何使用_cprintf()函数输出调试信息。
2358

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



