1.生成后事件 ——>命令行:editbin /subsystem:console $(OutDir)$(ProjectName).exe
2.
void CreateConsole( )
{
AllocConsole();
HANDLE handle_out = GetStdHandle(STD_OUTPUT_HANDLE);
int hCrt = _open_osfhandle((long) handle_out, _O_TEXT);
FILE* hf_out = _fdopen(hCrt, "w");
setvbuf(hf_out, NULL, _IONBF, 1);
*stdout = *hf_out;
HANDLE handle_in = GetStdHandle(STD_INPUT_HANDLE);
hCrt = _open_osfhandle((long) handle_in, _O_TEXT);
FILE* hf_in = _fdopen(hCrt, "r");
setvbuf(hf_in, NULL, _IONBF, 128);
*stdin = *hf_in;
// use the console just like a normal one - printf(), getchar(), ...
}
3.
AllocConsole();
freopen("conout$","w",stdout) ;
freopen("conout$","w",stderr) ;
4.
AllocConsole() ;
HANDLE hd = GetStdHandle(STD_OUTPUT_HANDLE) ;
WriteConsole(hd , "hello world" , sizeof("hello world") , NULL , NULL );
CloseHandle(hd) ;