MFC中增加輸出到控制檯

#include <io.h>
#include <stdio.h>
#include <fcntl.h>
void InitConsoleWindow()
{
    int nCrt = 0;
    FILE* fp;
    AllocConsole();
    nCrt = _open_osfhandle((long)GetStdHandle(STD_OUTPUT_HANDLE), _O_TEXT);
    fp = _fdopen(nCrt, "w");
    *stdout = *fp;
    setvbuf(stdout, NULL, _IONBF, 0);
}

在C**App的InitInstance()中添加如下:

BOOL CMFCTempleApp::InitInstance()
{
    InitConsoleWindow();
    printf( "str   =   %s\n ",   "debug");
發佈了36 篇原創文章 · 獲贊 21 · 訪問量 9萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章