原文链接

在GUI程序中使用printf函数:

 1 #include <io.h>
 2 #include <fcntl.h>
 3 
 4 void InitConsole()
 5 {
 6     int nRet= 0;
 7     FILE* fp;
 8     AllocConsole();
 9     nRet=_open_osfhandle((long)GetStdHandle(STD_OUTPUT_HANDLE), _O_TEXT);
10     fp = _fdopen(nRet, "w");
11     *stdout = *fp;
12     setvbuf(stdout, NULL, _IONBF, 0);
13 }

只要将上面的函数加到初始化的地方之后,就可以使用printf输出数据到console了,当然也可以使用cout输出。

相关文章:

  • 2021-05-08
  • 2021-11-17
  • 2022-12-23
  • 2021-11-27
  • 2021-12-17
  • 2022-12-23
  • 2021-08-03
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案