有时候因为各种原因会需要输出printf的打印信息,废话不多说如下(只要是Windows平台下的桌面程序都可以包括QT程序):
注。有些程序要加头文件如下:
#include <fcntl.h>
#include <io.h>
void CallConcoleOutput(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");
}
//在函数CDbgTestApp::InitInstance()中的所有代码前面调用该函数(注意:比如man函数和WINmain函数,其它地方调用无效):
InitConsoleWindow();
//后面你就可以使用printf输出运行信息了。