Contents ...
udn網路城邦
[C/C++] Windows 應用程式使用 Console Window 當作 Debugging Window
2015/11/25 17:40
瀏覽891
迴響0
推薦0
引用0

建立 Debugging Window:
.
// 記得要 #include 
.
// 建立一個新的 Console Window
AllocConsole();
.
// 將 stdin 、 stdout 、 stderr 弄到同一個 Console Window 中
freopen("conin$", "r", stdin);
freopen("conout$", "w", stdout);
freopen("conout$", "w", stderr);
.
// 這時候就可以透過剛剛建立的 Console Window 進行基本輸出 / 輸入操作
printf("This is a debugging window!!");

關閉 Debugging Window:
.
// 記得要 #include 
.
// 將 stdin 、 stdout 、 stderr 關閉
fclose(stdin);
fclose(stdout);
fclose(stderr);
.
// 將原本自己 process 的 Console Window 關閉
FreeConsole();

限會員,要發表迴響,請先登入