在 VS Code 中安装了 C/C++ 插件后会自动带上格式化工具 clang-format。按 option+shift+f
即可对文件进行 format(格式化)。
在目录下创建.clang-format
文件,可以指定格式化的规则。
Language: Cpp
BasedOnStyle: LLVM
DerivePointerAlignment: false
PointerAlignment: Left
AccessModifierOffset: -1
简单的方式是选一个基础 Style 如 LLVM,然后增加一些额外的设定。
比如我希望指针和引用的*
和 &
能紧靠类型,而不是变量名,就把 PointerAlignment
设置为 Left 即可。为了防止基础 Style 里用 DerivePointerAlignment 强制设定了 PointerAlignment,最好加上 DerivePointerAlignment: false
。
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有