Mik*_*ott 19 c++ code-formatting visual-studio-2010
我是Visual Studio中编写C++程序的新手.当我在VS中编写C#程序时,代码格式化程序会更改看起来像这样的代码
for(int i= 0; i<(n+ m) ; i++){
}
Run Code Online (Sandbox Code Playgroud)
成
for(int i = 0; i < (n + m); i++)
{
}
Run Code Online (Sandbox Code Playgroud)
这更容易阅读.当我用C++编写相同的东西时,没有任何反应.我试图选择文本并按Ctrl + E,F,但这不起作用.有没有办法在Visual Studio中改进C++代码格式化程序?
Visual Studio无法格式化C++ - 代码.也许有一个VS扩展.我搜索了很长时间,但从来没有找到一个合适的免费.
一个非常好的,免费但不易使用的代码格式化程序是GreatCode.它是一个命令行工具.
您可以将其配置为"外部工具":
在HD上打开GreatCode包装后,只需进入工具 - >外部工具 - >添加并插入以下设置......
无论何时调用该工具,都会格式化实际打开的文件.
您可以在gc.cfg中根据需要配置GreatCode.我尝试了很多选项,有些很容易,有些很复杂.
如果您想要类似Microsoft的外观,只需将我的设置用作模板并自行微调:
-code_constructor_style-1
-code_split_fctdef_style-5
-code_split_decl_style-2
-overwrite_read_only-
-verbose-
-tab_out-
-space_if-
-space_return-
-space_fctcall_inparam-
-no-space_fctcall_firstparam-
-no-space_cast_after-
-space_affect_style-0
-space_autoaffect_style-0
-code_len-180
-code_keep_more_empty_lines-
-code_decl_access_to_type-
-code_decl_break_template-
-code_remove_return_paren-
-code_align_max_blanks-80
-code_class_access_eol_after-1
-code_class_access_eol_before-1
-code_split_fctcall_style-1
-code_constructor_style-1
-no-code_split_bool_before-
-no-stmt_concat_else_if-
-no-stmt_decl_remove_empty-
-no-stmt_concat_if_remove_empty-
-no-stmt_concat_else_if-
-stmt_force_brace-1
-stmt_break_dowhile-
-stmt_switch_style-1
-stmt_switch_eol-0
-stmt_class_indent-0
-stmt_static_init_style-2
-stmt_concat_inline_class-
-pp_align_to_code-
-pp_style-1
-pp_align_breakline-
-no-cmt_first_space_cpp-
-cmt_dont_modify-
-no-cmt_add_class_access-
-no-cmt_add_gc_tag-
-no-cmt_add_fct_def_class-
-no-cmt_decl_before-
-no-cmt_decl-
-no-cmt_first_line_break_first-
-no-cmt_first_line_break_last-
-no-code_split_bool_before-
-catch_eol_before-1
-no-stmt_decl_remove_empty-
-no-cmt_add_fct_def_class-
-no-cmt_add_class_access-
-no-stmt_break_alone-
-stmt_concat_inline_class-
-cmt_keep_cpp-
Run Code Online (Sandbox Code Playgroud)
祝好运!
除了格式化工具本身,我使用与DirkMausF完全相同的方法.我建议你使用Artistic Style格式化程序:
http://astyle.sourceforge.net/
它有很好的文档,并带有许多预定义的格式样式,因此它非常易于使用.
归档时间: |
|
查看次数: |
11317 次 |
最近记录: |