使用 BOOST_FOREACH 时如何使 Eclipse CDT 自动缩进?
我在 Eclipse 3.4.1 (CDT 5.0.1) 中编写了这个小小的 C++ 示例:
#include <iostream>
#include <vector>
#include <boost/foreach.hpp>
int foo()
{
std::vector<int> numbers;
BOOST_FOREACH(int n, numbers)
{
std::cout << n << std::endl;
}
std::cout << numbers.size << std::endl;
}
然后我按 Shift+Ctrl+F 来格式化我的代码,它变成:
#include <iostream>
#include <vector>
#include <boost/foreach.hpp>
int foo()
{
std::vector<int> numbers;
BOOST_FOREACH(int n, numbers)
{ std::cout << n << std::endl;
}
std::cout << numbers.size << std::endl;
}
这是 BSD/Allman 代码风格。 其他样式显然会改变格式化代码的外观,但没有一个能够给出正确的缩进。
当我在较大的代码片段上使用格式功能时,后续的函数或方法也会受到缩进太少的影响,使得格式化帮助变得毫无帮助。
我可以做些什么来使缩进与 BOOST_FOREACH 一起正常工作吗?
I write this tiny C++ example in Eclipse 3.4.1 (CDT 5.0.1):
#include <iostream>
#include <vector>
#include <boost/foreach.hpp>
int foo()
{
std::vector<int> numbers;
BOOST_FOREACH(int n, numbers)
{
std::cout << n << std::endl;
}
std::cout << numbers.size << std::endl;
}
Then I hit Shift+Ctrl+F to format my code, and it becomes:
#include <iostream>
#include <vector>
#include <boost/foreach.hpp>
int foo()
{
std::vector<int> numbers;
BOOST_FOREACH(int n, numbers)
{ std::cout << n << std::endl;
}
std::cout << numbers.size << std::endl;
}
This is with the BSD/Allman Code Style. Other styles obviously vary the look of the formatted code, but none give correct indentation.
When I use the format feature on a larger piece of code, subsequent functions or methods are also affected by too little indentation, making the formatting help pretty unhelpful.
Is there something I can do to make the indentation work properly with BOOST_FOREACH?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可能想尝试 astyle eclipse 插件。 它似乎比 C++ 缩进的默认 eclipse 样式好得多。
You might want to try the astyle eclipse plugin. It seems to be much nicer than the default eclipse style of C++ indentation.
在当前的开普勒 CDT 中它仍然被破坏。 但是 Eclipse 的 Bugzilla 中有一个错误(请此处检查其状态)。 它最终会被修复:-)
It is still broken in the current CDT for Kepler. But there is a bug in Eclipse's Bugzilla (check its status here). It will eventually be fixed :-)
奇怪的是,这曾经与 CDT 4 一起使用。所以如果你真的需要这个,我建议你降级你的 CDT :-/
Strange, this used to work with CDT 4. So if you really really need this I suggest you downgrade your CDT :-/
呃……你不能吗? 尝试下一个版本的 CDT...:_(
Euh... you can't ? Try next version of CDT... :_(
将其添加到您的代码使用的某些标头中:
Add this to some header used by your code: