最佳 C++ 代码格式化器/美化器

发布于 2024-07-19 08:58:20 字数 138 浏览 4 评论 0原文

有很多源代码格式化工具。 哪些最适合 C++?

我对命令行工具或其他可以在签入/签出代码时自动运行的东西感兴趣,最好不需要启动编辑器或 IDE。

(如果您看到您喜欢的答案已列为答案,请将其投票。如果不存在,请添加它。)

There are lots of source code formatting tools out there. Which ones work best for C++?

I'm interested in command-line tools or other things that can be automatically run when checking code in/out, preferably without needing to launch an editor or IDE.

(If you see the one you like already listed as an answer, vote it up. If it's not there, add it.)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ㄖ落Θ余辉 2024-07-26 08:58:20

AStyle 可以针对 C++ 和 Java(以及其他语言)进行详细定制

这是一个源代码格式化工具。


clang-format 是一个强大的命令行工具,与clang 编译器能够以连贯的方式处理最晦涩的语言结构。

它可以与 Visual Studio、Emacs、Vim(和其他)集成,并且可以仅格式化选定的行(或使用 git/svn 来格式化一些差异)。

它可以使用此处列出的各种选项进行配置。

当使用配置文件(名为.clang-format)时,样式可以针对每个目录 - 父目录中最接近的此类文件应用于特定文件。

样式可以从预设(例如 LLVM 或 Google)继承,并且以后可以覆盖不同的选项。

它由 Google 和其他人使用,并且已准备好用于生产。


另请查看项目 UniversalIndentGUI。 您可以使用它尝试多种压头:AStyle、Uncrustify、GreatCode...并选择最适合您的压头。 其中任何一个都可以稍后从命令行运行。


Uncrustify 有很多可配置选项。 您可能还需要通用缩进 GUI(在 Konstantin 的回复中)来配置它。

AStyle can be customized in great detail for C++ and Java (and others too)

This is a source code formatting tool.


clang-format is a powerful command line tool bundled with the clang compiler which handles even the most obscure language constructs in a coherent way.

It can be integrated with Visual Studio, Emacs, Vim (and others) and can format just the selected lines (or with git/svn to format some diff).

It can be configured with a variety of options listed here.

When using config files (named .clang-format) styles can be per directory - the closest such file in parent directories shall be used for a particular file.

Styles can be inherited from a preset (say LLVM or Google) and can later override different options

It is used by Google and others and is production ready.


Also look at the project UniversalIndentGUI. You can experiment with several indenters using it: AStyle, Uncrustify, GreatCode, ... and select the best for you. Any of them can be run later from a command line.


Uncrustify has a lot of configurable options. You'll probably need Universal Indent GUI (in Konstantin's reply) as well to configure it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文