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

原文连接函数

在GUI程序中使用printf函数:spa

 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输出。.net

相关文章
相关标签/搜索