【VSCode】【C++】使用VSCode安裝使用C++
最後更新日期:2024年09月02日
安裝VSCode
下載網站: Download Visual Studio Code – Mac, Linux, Windows
安裝完成後,開啟一個新專案

下載 C 語言編譯器 – MinGW
下載網站: MinGW-w64 – Downloads
MinGW-W64-builds > 點擊「GitHub」進入 GitHub

點擊下載 64 位元的「x86_64-14.1.0-release-posix-seh-ucrt-rt_v12-rev0.7z」

解壓縮


設定系統變數
複製 mingw64 bin 資料夾路徑

系統 > 進階系統設定 > 環境變數 > 系統變數 > 點選 Path 變數 > 編輯


新增 > 貼上剛複製的路徑 > OK

測試是否可以使用 C++
打開新專案
Terminal > New Terminal


檢查編譯器版本
輸入 gcc-v

此時,就會出現編譯器版本代表設定成功!

安裝外掛 C/C++ Extension Pack
Extensions > C/C++ Extension Pack

寫一支程式印出 Hello World!
新增檔案 main.cpp

程式碼
#include <stdio.h>
int main()
{
printf("Hello World!");
}
輸入指令編譯成 exe檔 g++ <檔名> -o <自定義檔名>

輸入指令執行檔案 .\exe檔名
,輸出 Hello World!

就出現 Hello World! 囉,恭喜成功!!