--- Title: VSCode C++ tags: VSCode, computer --- # C++ 安裝在 VSCode 開啟```cmd```,輸入```where g++```,若有跳出路徑,無須安裝c++ ## VSCode and 環境變數 * 安裝 C/C++ 在VScode  * 設定環境變數 開啟檔案總管 ⇒ 電腦 ⇒ 內容 * 系統內容 ⇒ 選擇環境變數  * 環境變數 系統變數找到Path  * 編輯環境變數 新增 C:\MinGW\bin 點選確定  ## 撰寫 C/C++ - 設定單獨資料夾放C++的獨立環境 D:\project 創建HelloWorld.cpp 輸入程式碼: ```C++ #include <iostream> int main() { std::cout << "Hello World" << std::endl; } ``` 執行程式  ## .vscode 設置更換 將 tasks.json 改為tasks.json.txt 新增一個 settings.json 貼上下面內容 ```json { "code-runner.ignoreSelection": true, "code-runner.executorMap": { "cpp": "cd $dir & g++ -Wall -Wextra -O2 -std=c++14 \"$fileName\" -o \"$fileNameWithoutExt\" & $dir\"$fileNameWithoutExt\"" }, "code-runner.preserveFocus": false, "code-runner.clearPreviousOutput": true, "code-runner.runInTerminal": true, "code-runner.saveFileBeforeRun": true, "terminal.integrated.defaultProfile.windows": "Command Prompt", } ``` - Line 3 code-runner.executorMap 是設定副檔名為 xxx 時,作執行時會跑哪些命令。 - Line 4 設定 cpp 的執行命令。進入該檔案的資料夾,使用 g++ 加上其他參數編譯(也可以自行改 c++17),並且執行它。 - Line 7 清除上次在終端機執行的輸出。 - Line 8 在終端機上面跑,這一定要設定為 true,不然會跑到輸出,而非終端機。 - Line 9 執行前先存檔。 - Line 10 預設終端機改為 Windows Command Prompt
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up