1、先放出最终代码格式化结果
/*
* A sample source file for the code formatter preview
*/
#include <math.h>
class Point
{
public:
Point(double x, double y) : x(x), y(y)
{
}
double distance(const Point &other) const;
double x;
double y;
};
double Point::distance(const Point &other) const
{
double dx = x - other.x;
double dy = y - other.y;
return sqrt(dx * dx + dy * dy);
}
2、打开格式化面板Formatter
3 设定Tab为空格输入,调整各个模块缩进
4、调整声明相对位置、缩进等
6、快捷键设置
注意此处位于Window——》Preferences,与上面格式化代码位置不同!
选择 Format 在对应输入框键入习惯的快捷键即可。
5、补充
此外还有其它函数、块、if else语句等格式用法可根据需要调整