可以在CWinApp的InitInstance()中调用下面的函数,以生成控制台:
#include <io.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); }