Visual Studio Code(簡稱:Vscode) 是一個文本編輯器,支援語法突顯、程式碼補齊等等功能,簡單來說,就是一個強化版的 Windows 記事本,雖然預設已經支援許多程式語言,如 JavaScript、CSS、HTML 等等,如果要讓它執行更多種類的程式語言,如 C、C++、Python、Java 等等,就需要額外安裝工具和擴充功能。
Minimalist GNU for Windows(簡稱:MinGW) 是將 GCC 編譯和 GNU Binutils 移植到 Windows 環境上的版本,讓 C、C++ 能夠在 Windows 環境中運行。
本篇教學適用於 Windows 環境,將會使用 Vscode + MinGW 來搭建一個能夠撰寫 C++ 的 IDE。
更新訊息:
本篇教學中的 MinGW 工具版本較舊,雖然功能都能正常使用,但是可能無法支援 C++ 最新版本的工具,如果想使用 MinGW 的最新版本來撰寫 C++ 程式,可參考此篇教學文。
一、安裝 Vscode:
-
到 Vscode 官網下載 Vscode 的安裝檔。
連結:https://code.visualstudio.com/
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 →
-
安裝寫 C++ 必備和更便利的擴充功能,先進入到管理擴充功能的地方,點擊最左邊工具列四個框框的圖標或者按下快捷鍵 Ctrl + Shift + X。
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 →
二、安裝 MinGW:
-
到 SOURCEFORGE 網站下載 MinGW 的安裝檔。
連結:https://sourceforge.net/projects/mingw/files/
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 軟體,選擇 mingw32-gcc-g++ 會跳出一個清單,
接著按 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 →
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 Changes,接著按 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 →
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 →
三、設置 Windows 環境變數:
-
開啟電腦設定中的系統資訊,選擇關於標籤,點擊右邊的的進階系統設定。
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 →
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 加入到 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 →
四、設置 Vscode 環境:
-
到作者的 GitHub 下載設置 Vscode 環境需使用到的 Json 檔。
連結:https://github.com/smallshawn95/VSCode-CPP-Setting.git
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
-
創建一個之後要放 C++ 程式的資料夾,接著建立一個 .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 →
-
將剛剛下載好 Zip 檔解壓縮到 .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 →
-
按下快捷鍵 Ctrl + Shift + P 或者 F1,然後輸入 Open Setting,打開 Vscode Setting Json 檔。
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 Setting Json 檔中,這兩行程式都是避免 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 →
五、執行 Vscode 的第一個 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 →
-
寫出在 Vscode 中的第一個 C++ 程式 “Hello, world!” 吧。
- 如果在終端機成功顯示 “Hello, world!” 的話,恭喜您本次課程就成功了喔。
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 這個大家庭,作者當初會轉而使用 Vscode 的原因,就覺得 Dev-C++ 的顏色、主題和字體都不多,能夠個人化的空間不高,因此想要再看看有沒有其他工具能夠寫 C++,於是在網路上查詢到大多數人推薦使用 Vscode 寫程式,從此就不小心入坑 Vscode 了,不過,當時也是小白的我,想在 Vscode 中建置寫 C++ 的環境中就遇到頗多困難,網路上的教學雖然多,但是通常都教學步驟零零落落或是不夠詳細,讓當時的我吃足苦頭才做好一個能成功運行 C++ 的環境,因此想要製作一篇教學,來讓新手小白們也能輕鬆的建置好寫 C++ 的環境,在享受 Vscode 的便利和美麗的外觀的同時,也能快快樂樂的寫程式,歡迎大家一起加入程式這個大家庭。
Copyright © 2022 SmallShawn95. All rights reserved.