重定向标准输出到控制台

#ifdef DISPLAYCONSOLE
    // Redirection of standard output to console
    int hCrt;  BOOL rep;  FILE *hf;
    _SYSTEM_INFO lps;
    GetSystemInfo(&lps);
    rep = AllocConsole();
    hCrt = _open_osfhandle((long) GetStdHandle(STD_OUTPUT_HANDLE),_O_TEXT);
    hf = _fdopen( hCrt, "w" );
    *stdout = *hf;
    // stop the buffer on stdout
    //  int i = setvbuf( stdout, NULL, _IONBF, 0 );
    //  filebuf ff(hCrt);
    //  cout = &ff;
    printf("This Debug Window  will disappear in release mode\n");
    #endif //  DISPLAYCONSOLE

还需要在代码中声明

#define DISPLAYCONSOLE

 

posted @ 2015-04-23 00:59  穆穆里  阅读(1351)  评论(0编辑  收藏  举报