VSCODE格式化C/C++代码--配置clang-format

VSCODE格式化C/C++代码–配置clang-format

  1. vscode下载clang-format 扩展
    VSCODE格式化C/C++代码--配置clang-format
  2. :“ctrl+,”组合键打开setting配置界面,搜索“format”,根据需要配置"Format On Save",勾上则在保存文件时自动格式化
    VSCODE格式化C/C++代码--配置clang-format 如果不勾选的话,在文档中可以通过右键菜单或者快捷键来格式化
    VSCODE格式化C/C++代码--配置clang-format
  3. 找到clang-format.exe的安装路径,如果找不到,安装“everything”来搜索
    VSCODE格式化C/C++代码--配置clang-format
  4. 打开cmd,cd 到上述路径
    VSCODE格式化C/C++代码--配置clang-format
    VSCODE格式化C/C++代码--配置clang-format
  5. 输入以下命令
    clang-format -style=llvm -dump-config > .clang-format
    生成红框中的.clang-format文件
    VSCODE格式化C/C++代码--配置clang-format
  6. 将此文件拷贝到工程根目录下,如我的根目录如下
    VSCODE格式化C/C++代码--配置clang-format
  7. 根据需要修改这个配置文件,一般只修改下面内容
    VSCODE格式化C/C++代码--配置clang-format
    参考文章:
    https://blog.****.net/core571/article/details/82867932
    https://www.jianshu.com/p/c2dd26fe6f78