#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