我在 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 一起正常工作吗?