//在Windows程序中打开控制台的程序
#include <stdio.h>
#include <io.h>
#include <fcntl.h>
BOOL CreateConsole(void)
{
FreeConsole();
if ( AllocConsole() )
{
int hCrt = _open_osfhandle((long)
GetStdHandle(STD_OUTPUT_HANDLE), _O_TEXT);
*stdout = *(::_fdopen(hCrt, "w"));
::setvbuf(stdout, NULL, _IONBF, 0);
*stderr = *(::_fdopen(hCrt, "w"));
::setvbuf(stderr, NULL, _IONBF, 0);
return TRUE;
}return FALSE;
}
在程序启动时调用该函数即可