【问题标题】:Visual Code C/C++ formatting of braces {}大括号 {} 的 Visual Code C/C++ 格式
【发布时间】:2021-04-03 17:26:41
【问题描述】:

在 VSCode 中,我希望我的左大括号 { 位于同一行,而不是新行,为此我将 C_Cpp.clang_format_fallbackStyle 从 Visual Studio 更改为 LLVM,这似乎可行。

但它做了我不想要的事情,它像这样格式化我的 if-else 语句:

if (condition){
    do_something()
} else {
    do_something_else()
}

相反,我希望它是这样的:

if (condition){
    do_something()
} 
else {
    do_something_else()
}

基本上,我希望每个右括号都在线,无论是用于 if-else 语句还是 try-catch 或其他。 我该怎么做?

【问题讨论】:

    标签: c++ c visual-studio-code vscode-settings


    【解决方案1】:

    在您的 VS Code 设置中应该能够执行类似
    "C_Cpp.clang_format_fallbackStyle": "{ BasedOnStyle: LLVM, BreakBeforeBraces: Custom, BraceWrapping: { BeforeElse: true }"

    欲了解更多信息:
    https://clang.llvm.org/docs/ClangFormatStyleOptions.html
    Visual Studio Code formatting for "{ }"
    https://code.visualstudio.com/docs/cpp/cpp-ide

    【讨论】:

    • @SatvikGupta 那么您介意将其标记为已接受吗?谢谢
    猜你喜欢
    • 2020-07-21
    • 2017-12-03
    • 2019-01-04
    • 2018-08-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-25
    • 2018-05-01
    相关资源
    最近更新 更多