将下面这段代码加入到MFC程序初始化的地方
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);
}
注意要添加下列头文件:
#include <io.h>
#include <fcntl.h>