Eclipse c ++格式化数组初始值设定项

时间:2012-10-26 20:01:01

标签: c++ eclipse formatting array-initialization

eclipse格式化数组初始化程序的方式非常糟糕。我知道你可以调整它在首选项中的格式,但它总是会在' ='之间添加换行符。和" {...}'。

这对我来说非常难看,特别是当你有一个空的初始化程序时。

有没有办法进一步调整这些设置,因此它永远不会放置换行符,或者它只是单独留下数组初始值设定项,只在逗号和初始化程序的元素之间放置适当数量的空格?

作为一个例子,这就是我想要它的方式:

string shortArray[15] = { };
string notVeryLong[] = { "Some words", "More words", "and more", "etc" };
string TooLongForOneLine[] = 
{
    "Some words", "More words", "and more", "etc", 
    "Some words", "More words", "and more", "etc", 
    "Some words", "More words", "and more", "etc", 
    "Some words", "More words", "and more", "etc", 
    "Some words", "More words", "and more", "etc", 
    "Some words", "More words", "and more", "etc", 
    "Some words", "More words", "and more", "etc", 
    "Some words", "More words", "and more", "etc", 
    "Some words", "More words", "and more", "etc" 
};

1 个答案:

答案 0 :(得分:0)

我不确定您使用的是哪个版本的Eclipse,但我会回答Eclipse 3.7的问题,因为这是我使用的。

  1. 打开“Windows”下拉菜单,然后选择首选项。
  2. 然后导航到“C ++”,然后导航到“Code Style”。
  3. 选择“新建...”按钮。提供名称并选择一个内置配置文件。
  4. 转到“大括号”标签。在列表的底部有一个“初始化列表”下拉列表。从下拉列表中选择“相同行”,然后单击“确定”按钮以关闭所有对话框。
  5. 注意:在同一窗口区域中,您可以自定义类,函数,命名空间,if语句,switch语句等的大括号。