在vscode中快捷键ctrlshiftp然后输入setting会出现下图几个选项当不同设置之间出现冲突时听谁的Open Workspace Settings(JSON) Open Settings(JSON) Open User Settings Open Default Settings(JSON)Open Workspace Settings(JSON)点击该选项会在当前工程目录下新建一个.vscode目录在.vscode目录下会多出一个settings.json文件默认为空。在这个settings.json文件中可以写一些设置选项这些设置选项仅仅对当前工程目录下的文件起作用.c_cpp_properties.json此文件用于配置VS Code的C/C扩展提供正确的IntelliSense代码完成、提示等。官网链接https://code.visualstudio.com/docs/cpp/c-cpp-properties-schema-reference模板为{env:{//定义了一组环境变量这些变量稍后在配置中可以引用myDefaultIncludePath:[${workspaceFolder},${workspaceFolder}/include],//表示默认的头文件搜索路径myCompilerPath:/usr/local/bin/gcc-7//定义了一个编译器的路径},configurations:[{name:Mac,//mac,linux,win32/描述了这个配置的目的或使用的环境intelliSenseMode:clang-x64,includePath:[${myDefaultIncludePath},/another/path],//包含头文件搜索路径的数组。它引用了前面定义的环境变量myDefaultIncludePath并添加了另一个路径/another/pathmacFrameworkPath:[/System/Library/Frameworks],defines:[FOO,BAR100],forcedInclude:[${workspaceFolder}/include/config.h],compilerPath:/usr/bin/clang,//用于构建项目的编译器的完整路径cStandard:c11,cppStandard:c17,compileCommands:/path/to/compile_commands.json,//指向一个compile_commands.json文件的路径它提供了关于如何编译工程中各个文件的信息browse:{path:[${workspaceFolder}],limitSymbolsToIncludedHeaders:true,databaseFilename:}}],version:4}launch.json官网链接https://code.visualstudio.com/docs/cpp/launch-json-referencelaunch.json 文件用于在 Visual Studio Code 中配置调试器。要开始调试您需要在program字段中填写您计划调试的可执行文件的路径。This must be specified for both the launch and attach (if you plan to attach to a running instance at any point) configurations.生成的文件包含两部分第一部分配置launch调试第二部分配置attach调试点击DEBUG-创建lauch.json配置vscode调试行为Set or change the following options to control VS Code’s behavior during debugging:例子{name:C Launch (Windows),type:cppvsdbg,request:launch,program:C:\\app1\\Debug\\app1.exe,symbolSearchPath:C:\\Symbols;C:\\SymbolDir2,externalConsole:true,logging:{moduleLoad:false,trace:true},visualizerFile:${workspaceFolder}/my.natvis,showDisplayString:true}program (required)指定调试器将启动或附加的可执行文件的完整路径。调试器需要该位置才能加载调试符号。symbolSearchPath告诉 Visual Studio Windows 调试器搜索symbol(.pdb) 文件的路径。用分号分隔多个路径。例如C:\Symbols;C:\SymbolDir2。requireExactSourceadditionalSOLibSearchPathTells GDB or LLDB what paths to search for .so files. Separate multiple paths with a semicolon. For example:/Users/user/dir1;/Users/user/dir2.externalConsoleUsed only when launching the debuggee. Forattach, this parameter does not change the debuggee’s behavior.Linux: set to true,通知 VS Code 生成外部控制台set to false使用vscode终端avoidWindowsConsoleRedirectionlogging可选标记用于确定哪些类型的信息应记录到调试控制台。exceptions可选标志用于确定是否将异常信息记录到调试控制台。默认为 true。moduleLoad模块加载可选标记用于确定是否将模块加载事件记录到调试控制台。默认为 true。programOutput程序输出可选标志用于确定是否将程序输出记录到调试控制台。默认为 true。engineLogging引擎记录可选标记用于确定是否将诊断引擎日志记录到调试控制台。默认为 false。trace跟踪可选标记用于确定是否将诊断适配器命令跟踪记录到调试控制台。默认为 false。traceResponse跟踪响应可选标记用于确定是否将诊断适配器命令和响应跟踪记录到调试控制台。默认为假。自定义GDB或LLDBhttps://blog.csdn.net/weixin_40579705/article/details/133788557?spm1001.2014.3001.5501存在远程debug容器中的tasks.json官网链接https://code.visualstudio.com/Docs/editor/tasks此文件定义了在VS Code中执行的任务。这些任务可以是编译、构建、运行脚本等。ctrlshiftp-task-使用模板创建tasks.json文件-others 运行任何外部命令的先例以下为自定义task{// See https://go.microsoft.com/fwlink/?LinkId733558// for the documentation about the tasks.json formatversion:2.0.0,tasks:[{label:Run tests,type:shell,command:./scripts/test.sh,windows:{command:.\\scripts\\test.cmd},group:test,presentation:{reveal:always,panel:new}}]}label用户界面中使用的任务标签type任务类型。对于自定义任务可以是 shell 或进程。如果指定 shell命令将被解释为 shell 命令例如bash、cmd 或 PowerShell。如果指定 process命令将被解释为一个要执行的进程。command要执行的实际命令。groupDefines to which group the task belongs. In the example, it belongs to thetestgroup. Tasks that belong to the test group can be executed by runningRun Test Taskfrom theCommand Palette.presentationoptions覆盖 cwd当前工作目录、env环境变量或 shell默认 shell的默认值。选项可按任务设置也可全局或按平台设置。此处配置的环境变量只能在任务脚本或进程中引用如果它们是 args、命令或其他任务属性的一部分则不会被解析。runOptionsDefines when and how a task is run示例使用g编译c程序{version:2.0.0,tasks:[{label:g build active file,type:shell,command:/usr/bin/g,args:[-g,${file},-o,${fileDirname}/${fileBasenameNoExtension}],options:{cwd:${workspaceFolder}},problemMatcher:[$gcc],group:{kind:build,isDefault:true}}]}setting.json官网链接https://code.visualstudio.com/docs/getstarted/settings可以根据自己的喜好通过各种配置来配置vscode。几乎vscode的编辑器用户界面和功能行为的每个部分都有可以修改的地方不同的设置范围:用户设置全局应用到你打开的任何vscode实例的设置工作区设置存储在工作区内部的设置仅在工作区打开时应用https://blog.csdn.net/weixin_40579705/article/details/131492235?spm1001.2014.3001.5501