[C/C++] Windows 應用程式使用 Console Window 當作 Debugging Window - 又在碎碎念惹 - udn部落格
又在碎碎念惹
作家:又在碎碎念惹
文章分類
    Top
    [C/C++] Windows 應用程式使用 Console Window 當作 Debugging Window
    2015/11/25 17:40:36
    瀏覽:927
    迴響: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();
    回應

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