求大家帮忙看下,输出结果里的一大段空格是哪来的,应该怎么删除
#include <iostream>#include<cmath>
#include<iomanip>
using namespace std;
class Point
{
public:
void setPoint(float x,float y)
{
m_x=x;
m_y=y;
}
float length()
{
cout<<setiosflags(ios::fixed);
cout.precision(2);
return sqrt(m_x*m_x+m_y*m_y);
}
private:
float m_x,m_y;
};
int main()
{
int x,y;
Point p;
float q[5];
int i,j;
for(i=0;i<5;i++)
{
cin>>x>>y;
p.setPoint(x,y);
q[i]=p.length();
}
for(i=0;i<5;i++)
{
for(j=i+1;j<5;j++)
{if(q[i]>q[j])
{
float t=q[i];
q[i]=q[j];
q[j]=t;
}
}
}
cout<<"与原点的距离:"<<endl;
for(i=0;i<5;i++)
{
cout<<q[i]<<" ";
}
return 0;;
}
输出结果为
与原点的距离:
3.16 3.61 6.40 6.71 10.63