Linux
Linux下includePath路徑:(C++頭文件)
/usr/include/
/usr/local/include/
Linux下minDebuggerPath路徑:(gdb調試)
/usr/bin/gdb
Linux下compilerPath路徑:(gcc編譯)
/usr/bin/gcc
- c_cpp_properties.json配置文件
{
"configurations": [
{
"name": "Win32",
"includePath": [
"/usr/include/*",
"/usr/local/include/*"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "/usr/bin/gcc",
"cStandard": "c11",
"cppStandard": "c++14",
"intelliSenseMode": "clang-x64"
}
],
"version": 4
}
- launch.json
{
"version": "0.2.0", //2019
"configurations": [
{
"name": "(gdb) Launch", // 配置名稱,將會在啟動配置的下拉菜單中顯示
"type": "cppdbg", // 配置類型,這里只能為cppdbg
"request": "launch", // 請求配置類型,可以為launch(啟動)或attach(附加)
"program": "${workspaceRoot}/${fileBasenameNoExtension}.exe",// 將要進行調試的程序的路徑
"args": [], // 程序調試時傳遞給程序的命令行參數,一般設為空即可
"stopAtEntry": false, // 設為true時程序將暫停在程序入口處,一般設置為false
"cwd": "${workspaceRoot}", // 調試程序時的工作目錄,一般為${workspaceRoot}即代碼所在目錄
"environment": [],
"externalConsole": true, // 調試時是否顯示控制台窗口,一般設置為true顯示控制台
"MIMode": "gdb",
"miDebuggerPath": "/usr/bin/gdb", // miDebugger的路徑,注意這里要與MinGw的路徑對應
"preLaunchTask": "g++", // 調試會話開始前執行的任務,一般為編譯程序,c++為g++, c為gcc
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
- task.json
{
"version": "2.0.0",
"command": "g++",
"args": ["-g","${file}","-o","${fileBasenameNoExtension}.exe"], // 編譯命令參數
"problemMatcher": {
"owner": "cpp",
"fileLocation": ["relative", "${workspaceRoot}"],
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
}
}
Windows
其它選項基本與Linux相同,只有c_cpp_properties.json與launch.json部分選項需要修改。
c_cpp_properties.json
includePath
由於Windows以及VSCode沒有預裝好編譯環境,不像Linux把所有的東西都備好了。
所以,需要自己安裝mingw或者DevC++、CodeBlocks等自帶完備環境的ide。
由於我預裝了DeVC++,所以此處用DevC++文件夾下mingw的庫文件以及gdb、gcc等
"C:/Program Files (x86)/Dev-Cpp/MinGW64/include/*",
"C:/Program Files (x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/*"
compilerPath
"C:\\Program Files (x86)\\Dev-Cpp\\MinGW64\\bin\\gcc.exe",
launch.json
miDebuggerPath
"C:\\Program Files (x86)\\Dev-Cpp\\MinGW64\\bin\\gdb.exe", //注意
這里要與MinGw的路徑對應
windows下需要重新設置系統環境變量,將mingw下的bin文件添加到Path中去,重啟電腦。
VScode插件設置
C/C++ //必要的
C++Intellisense
Chinese(Simplified) //英語大佬可以不需要
Code Runner //必要的
Eslint //彩虹大括號
Project Manager
RainBow Brackets //彩虹小括號