Try   HackMD

用 VSCode 寫 C/C++ 教學

VSCode 安裝

  • 前往 VSCode 網站下載安裝檔
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  • 下載後開啟安裝程式
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  • 同意使用者條款
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  • 選擇下面的勾勾
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  • 確認安裝
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  • 安裝完成,會自動打開 VSCode
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  • 進入 Extenion
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  • 安裝 C/C++
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  • 安裝 C++ Intellisense
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

MinGW 安裝

(這個mingw是較舊的版本,比較新的好像是mingw-w64的樣子?放個小註解在這裡,看看有沒有大神要幫忙修改完整的說明)

  • 進入 MinGW 下載頁面選取 mingw-get-setup.exe (檔案會自動下載)
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  • 開啟下載下來的程式,選擇下一步

    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  • 選擇安裝位置後繼續 (與描述檔有關,除非你知道怎麼弄否則不要動)
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  • 安裝畫面

    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  • 安裝完後會啟動 MinGW Installer Manager,找到 mingw32-gcc-g++ (bin) 點取左方窗格,選擇 Mark for Installation
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  • 選左側 All Packages,找到 mingw32-gdb (bin) 點取左方窗格,選擇 Mark for Installation
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  • 選擇 Installation > Apply Change
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  • 點選 Apply

    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  • 安裝中,安裝完成後點選 Close

    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  • 開啟檔案總管 > 電腦 > 內容
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  • 選取右側側進階系統設定
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  • 選擇環境變數

    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  • 在下面的系統變數找到 Path

    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  • 新增 C:\MinGW\bin 點選確定

    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  • 環境變數變更完畢後重新啟動

開始撰寫 C/C++

  • 在桌面上隨意新增資料夾

  • 進入 repository 主頁,選擇 Clone or Download > Download ZIP
  • 或在終端機輸入 git clone https://github.com/liaojason2/vscode-cpp-for-windows.git
  • 在剛剛在桌面上的資料夾中新增 .vscode 資料夾
  • 解壓縮後從下載下來的東西加入畫面中(畫面的四個檔案)
  • 在桌面上對資料夾點選右鍵,選擇以 Code 開始

  • 點選資料按鈕新增檔案,取完檔名後開始輸入程式
  • 輸入 Ctrl+Shift+B 進行編譯
  • 輸入 Ctrl+Shift+` 開啟終端機
  • 輸入 ./<檔名>.exe+Enter執行程式

注意事項

  • .vscode 必須與要編譯的檔案在同一個資料夾或是任一上層目錄
  • vscode 必須以資料夾方式開啟才能編譯,即使是只寫一個檔案也一樣