在VS界面程序中显示命令行窗口

来源:互联网 发布:qt 64位 windows 编辑:程序博客网 时间:2024/06/05 11:04

在主程序中加入下面这个函数

#include <io.h>

#include <fcntl.h>
#include <Windows.h>
void InitConsoleWindow(void)
{
  int hCrt;
  FILE *hf;
  AllocConsole();
  hCrt = _open_osfhandle(
    (long)GetStdHandle(STD_OUTPUT_HANDLE),
    _O_TEXT);
  hf = _fdopen(hCrt, "w");
  *stdout = *hf;
  setvbuf(stdout, NULL, _IONBF, 0);


  // test code ...
  printf("InitConsoleWindow OK!\n\n");
}
0 0
原创粉丝点击