You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何让VS Code中clang-format将空循环的分号置于同一行?

问题:强制VS Code保留分号位置,避免分号单独换行

我希望VS Code格式化代码时,将分号保留在循环语句的同一行,避免出现以下格式:

for (int i = 0; i < 10000; i++)
    ;

改为目标格式:

for (int i = 0; i < 10000; i++);

当前我的VS Code设置如下:

"C_Cpp.clang_format_style":  { 
    BasedOnStyle: WebKit,  
    ColumnLimit: 120, 
},
临时解决方案

经提示,使用{}是clang-format的可行变通方案。经过多小时尝试,我发现vcFormat(基于clang)可正常处理该格式问题,因此已弃用clang-format,更新后的设置如下:

{
    "C_Cpp.formatting": "vcFormat",
}

内容的提问来源于stack exchange,提问作者yo3hcv

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.28 10:55:00