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");

你可能感兴趣的:(mfc)