#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 "); #endif // DISPLAYCONSOLE
还需要在代码中声明
#define DISPLAYCONSOLE