MFC窗体程序中添加调试控制台

在编写复杂程序的过程中,我们经常需要将一些信息输出到文件或者屏幕上。较控制台应用程序,MFC窗体程序要显得麻烦一些!

需要包含的头文件

#include <io.h>
#include <cstdio>
#include <FCNTL.H>

使用

开启

AllocConsole();
intptr_t handle= (intptr_t)GetStdHandle(STD_OUTPUT_HANDLE);
int hCrt = _open_osfhandle(handle,_O_TEXT);
FILE * hf = _fdopen( hCrt, "w" );
*stdout =*hf;

关闭

FreeConsole();
posted @ 2019-05-19 11:58  youngliu91  阅读(227)  评论(0编辑  收藏  举报