gpt4 book ai didi

c++ - astyle 可以处理不同的数组初始化大括号吗?

转载 作者:太空狗 更新时间:2023-10-29 22:58:48 26 4
gpt4 key购买 nike

我有以下代码片段,这正是我想要的:

#include <iostream>

int main(int argc, char* argv[])
{
for (auto i: { 1, 2, 3 })
{
std::cout << i << std::endl;
}
}

不幸的是,astyle 把它变成了:

#include <iostream>

int main(int argc, char* argv[])
{
for (auto i :
{
1, 2, 3
})
{
std::cout << i << std::endl;
}
}

有什么方法可以使 astyle 以不同方式处理初始化列表大括号(即忽略它们)?

这些是我目前的选择:

--mode=c --style=allman --indent=spaces=4 -max-code-length=100 --attach-namespaces --pad-oper --pad-header

最佳答案

只需添加选项--keep-one-line-blocks所以,所有选项都是

--mode=c --style=allman --indent=spaces=4 --max-code-length=100 --attach-namespaces --pad-oper --pad-header --keep-one-line-blocks


#include <iostream>

int main( int argc, char* argv[] )
{
for ( auto i : { 1, 2, 3 } )
{
std::cout << i << std::endl;
}

bool br = false;
if ( true )
{ br = true; cout << "Just test" << endl; }
}

但是,您应该小心。添加 --keep-one-line-blocks 选项后,astyle 只保留所有一行 block ,例如最后一行。

关于c++ - astyle 可以处理不同的数组初始化大括号吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39510081/

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