VSCode是個編輯器,默認不帶編譯和調試環境,須要自行安裝編譯器,調試能夠用其插件完成。html
編譯套件選用的是TDM-GCC,方便易用。(Codeblocks、Dev-Cpp等默認帶的都是這款)。安裝時會自動添加路徑到環境變量PATH。c++
{ "version": "0.2.0", "configurations": [{ "name": "C Launch (GDB)", // 配置名稱,將會在啓動配置的下拉菜單中顯示 "type": "cppdbg", // 配置類型,這裏只能爲cppdbg "request": "launch", // 請求配置類型,能夠爲launch(啓動)或attach(附加) "launchOptionType": "Local", // 調試器啓動類型,這裏只能爲Local "targetArchitecture": "x86", // 生成目標架構,通常爲x86或x64,能夠爲x86, arm, arm64, mips, x64, amd64, x86_64 "program": "${cwd}\\${fileBasenameNoExtension}.exe", // 將要進行調試的程序的路徑 "miDebuggerPath": "gdb32.exe", // miDebugger的路徑,注意這裏要與MinGw的路徑對應。64位系統用gdb64.exe "args": [""], // 程序調試時傳遞給程序的命令行參數,通常設爲空便可 "stopAtEntry": false, // 設爲true時程序將暫停在程序入口處,我通常設置爲true "cwd": "${workspaceRoot}", // 調試程序時的工做目錄,通常爲${workspaceRoot}即代碼所在目錄 "externalConsole": true, // 調試時是否顯示控制檯窗口,通常設置爲true顯示控制檯 "preLaunchTask": "gcc" // 調試會話開始前執行的任務,通常爲編譯程序,c++爲g++, c爲gcc }] }
{ "version": "0.1.0", "command": "gcc", // 編譯C++用g++,用MinGW和clang的自行修改。 "args": ["${file}", "-o", "${fileBasenameNoExtension}.exe", "-g3", "-Og", "-Wall", "-static-libgcc", "-std=c11", "-fexec-charset=GBK", "-finput-charset=UTF-8"], // 編譯命令參數,C++可用-std=c++14 "showOutput": "always", "problemMatcher": { "owner": "c", "fileLocation": ["relative", "${workspaceRoot}"], "pattern": { "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$", "file": 1, "line": 2, "column": 3, "severity": 4, "message": 5 } } }
// 將設置放入此文件中以覆蓋默認值和用戶設置。 { "files.defaultLanguage": "c", "code-runner.runInTerminal": false, "code-runner.executorMap": { "c": "cd $dir && gcc $fileName -o $fileNameWithoutExt -Wall -g3 -Og -static-libgcc -std=c11 && $dir$fileNameWithoutExt", "cpp": "cd $dir && g++ $fileName -o $fileNameWithoutExt -Wall -g3 -Og -static-libgcc -std=c++14 && $dir$fileNameWithoutExt" } }
// 目錄根據實際修改 { "configurations": [ { "name": "Win32", "includePath": [ "${workspaceRoot}", "C:/TDM-GCC-32/include", "C:/TDM-GCC-32/lib/gcc/mingw32/5.1.0/include" ], "browse": { "limitSymbolsToIncludedHeaders": true, "databaseFilename": "", "path": [ "C:/TDM-GCC-32/include", "C:/TDM-GCC-32/lib/gcc/mingw32/5.1.0/include" ] } } ], "clang_format": { "style": "file", "fallback-style": "LLVM", "sort-includes": false } }
7.在當前目錄下新建一個.c文件,在調試面板中測試啦,或直接按F5。shell
參考文章:json