1.设置格式化代码大括号“{”不换行
- 文件(File)–>首选项(Preferences)–>设置(settings)
- 搜索brace
- C_Cpp: Clang_format_fallback Style默认为Visual Studio,改为{ BasedOnStyle: Chromium, IndentWidth: 2}
- 第二个设置是缩进
2.配置单步调试
-
Ctrl+Shift+p,选择C/C++:Edit Configurations(JSON),主要添加头文件路径
-
Ctrl+Shift+p,选择tasks: Configure Task,根据需求修改command,args,group,presentation
-
{ // See https://go.microsoft.com/fwlink/?LinkId=733558 // for the documentation about the tasks.json format "version": "2.0.0", "tasks": [ { "type": "shell", "label": "make", "command": "cd build && cmake . && make", "args": [ ], "group": {"kind":"build","isDefault":true}, "presentation": { "reveal": "always"//可选always或者silence,代表是否输出信息 }, "problemMatcher": "$msCompile" } ] }
-
-
点击左侧工具栏”Debug“(小虫),点击”齿轮“按钮,此时.vscode文件夹下面就会自动生成launch.json文件,将program的值改为可执行程序的路径。同时,可以使用"preLaunchTask"选项在调试前自动编译。
-
笔者遇到了断点无效的情况,是因为在编译的时候没有-g选项,需要在CMakeLists.txt中加入add_compile_options(-g)