gpt4 book ai didi

c++ - 在 Visual Studio 2013 中自动 c++ 源代码格式化

转载 作者:太空宇宙 更新时间:2023-11-04 13:00:35 25 4
gpt4 key购买 nike

如何在所有项目中格式化或对齐 Visual Studio 2013 中的多个 c++ 源代码?

是否有机会创建一个我可以跨项目使用的单独模板?

一个带有实际代码的例子:

for(int i= 0; i<(n+  m) ;  i++){
}

所需代码的示例:

for ( int i = 0; i < (n + m); i++ )
{
}

我对实际文档使用 CTRL+K -> CTRL+D 格式,对实际选择使用 CTRL+K -> CTRL+F 格式。但这不能满足我的个性化要求。我如何根据自己的要求配置它?

如果 visual studio 2013 上没有可用的工具,我会寻找插件。

最佳答案

试试 AStyle 插件:https://marketplace.visualstudio.com/items?itemName=Lukamicoder.AStyleExtension

将其设置为format on save 然后ctrl+s 成为格式化命令(如果你希望它经常格式化)。另外,通过使用 AStyle,您可以 heavily customize符合您的格式约定。


我们还使用 astyle 配置文件,并有一个构建服务器定期对 repo 执行格式化。您可以使用批处理文件执行相同的操作:

:: This script can be setup to run on a daily or weekly basis to clean up code commits

:: TODO : add directories and options for formatting
astyle --options=config.astyle -r ..\..\Source\*.cpp

:: TODO : add directories and messages for committing.
svn commit -m "[AUTO] Astyle Autoformatting" ..\..\Source\

config.astyle 的样子:

--suffix=none # do not retain a backup of the original file

--style=allman

--indent=spaces=4
--convert-tabs

--indent-switches
--pad-oper

--align-pointer=type
--align-reference=type

--max-instatement-indent=40

--keep-one-line-blocks
--keep-one-line-statements

根据您的口味。

关于c++ - 在 Visual Studio 2013 中自动 c++ 源代码格式化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44353796/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com