我在 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 一起正常工作吗?
最佳答案
将此添加到您的代码使用的某些 header 中:
#ifdef __CDT_PARSER__
#undef BOOST_FOREACH
#define BOOST_FOREACH(a, b) for(a; ; )
#endif
关于c++ - 使用 BOOST_FOREACH 时如何使 Eclipse CDT 自动缩进?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/366380/