重定向标准输出到控制台

#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

 

你可能感兴趣的:(重定向)