MFC的GUI窗口使用Console输出函数printf

来源:互联网 发布:如何备考司法考试知乎 编辑:程序博客网 时间:2024/06/05 20:58

http://blog.csdn.net/VisualEleven/article/details/5517541


在GUI程序中使用printf函数:

 

[cpp] view plaincopy
  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输出。

原创粉丝点击