C++ MFC控制台输出调试信息

1、#include <conio.h>

2、在需要开启控制台窗口的地方调用
AllocConsole();//注意检查返回值 3、在需要输出调试的时候调用_cprintf等函数
如_cprintf("i=%d\n", i); 4、关闭控制台的时候调用
FreeConsole(); 注意:上述方法在输出中文时会出现乱码,如果需要输出中文,请使用下面的方法:
AllocConsole();
freopen( "CONOUT$","w",stdout);
printf("i的值为%d\n", i);
FreeConsole();
方法二:
#include <io.h>
#include <fcntl.h> void InitConsoleWindow()
{
AllocConsole();
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
int hCrt = _open_osfhandle((long)handle,_O_TEXT);
FILE * hf = _fdopen( hCrt, "w" );
*stdout = *hf;
}
BOOL CHelloMFCDlg::OnInitDialog()
{
CDialog::OnInitDialog(); InitConsoleWindow(); // add
printf("str = %s\n ", "Debug output goes to terminal\n");
......
}
上一篇:winform里dataGridView分页代码,access数据库


下一篇:好用的排名函数~ROW_NUMBER(),RANK(),DENSE_RANK() 三兄弟