原文連接函數
在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