安裝vscdoe,安裝tdm-gcc-64編譯器,這樣可以自動把mingw的目錄添加到環境變量中,其實安裝其他編譯器本版都可以,只要手動添加環境變量即可。平台win10-64位。
此文參考了嗶哩嗶哩的配置教程:https://www.bilibili.com/video/av11134188/?p=3
在任何位置新建一個文件夾,比如CPPsrc。
右鍵vscode打開,在左側的資源管理器中新建c++文件。
這樣,vscode可以在CPPsrc目錄下自動生成.vscode子文件夾,里面有launch.json和tasks.json。
安裝C/C++插件。
安裝coderunner插件,具體可以百度怎么配置。
tasks.json配置如下 { "tasks": [ { "type": "shell", "label": "g++.exe", "command": "C:/TDM-GCC-64/bin/g++.exe", "args": [ "-g", "${file}", "-o", "${fileDirname}\\${fileBasenameNoExtension}.exe" ], "options": { "cwd": "C:/TDM-GCC-64/bin" } }, { "type": "shell", "label": "g++.exe", "command": "C:/TDM-GCC-64/bin/g++.exe", "args": [ "-g", "${file}", "-o", "${fileDirname}\\${fileBasenameNoExtension}.exe" ], "options": { "cwd": "C:/TDM-GCC-64/bin" }, "problemMatcher": [ "$gcc" ] } ], "version": "2.0.0" } launch.json配置如下: { // 使用 IntelliSense 了解相關屬性。 // 懸停以查看現有屬性的描述。 // 欲了解更多信息,請訪問: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0", "configurations": [ { "name": "g++.exe build and debug active file", "type": "cppdbg", "request": "launch", "program": "${fileDirname}\\${fileBasenameNoExtension}.exe", "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": true, "MIMode": "gdb", "miDebuggerPath": "C:/TDM-GCC-64/gdb64/bin/gdb.exe", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ], "preLaunchTask": "g++.exe" } ] }
編寫C++代碼可以在文件中,直接右鍵,會出現“run code”,vscode 的下邊欄的輸出可以輸出結果了,類似於cmd中運行一樣。

