场景:在Qt里,不能使用std::cout在 "输出" 下输出信息,所以使用下面的函数就可以打印cout的内容了
#include <io.h> #include <fcntl.h> static void OpenConsole() { AllocConsole(); HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE); int hCrt = _open_osfhandle((long)handle,_O_TEXT); FILE * hf = _fdopen( hCrt, "w" ); *stdout = *hf; }
原文地址:http://blog.csdn.net/taoerit/article/details/39010023