C ++为什么我的程序不起作用......:S

时间:2015-04-30 14:08:05

标签: c++

这是我的计划...... 我试图通过循环从文件读取2D点,并找到每次与另一个点r(x,y)的距离。所有数据都必须从文件中获取......

包含“r”的文件名为Robot_point.dat,只是一个由空格分隔的2个数字的文件:

4 2.5

包含这些点的文件名为Polygons.dat,形成如下:

5 1 2 2 1 3 2 2.5 3 2 3

5号参考点的数量(实际上是多边形的顶点)。每对数字都是一个点。

我写了这个程序,但....它没有用,我不明白为什么我是C ++新手

#include <math.h>
#include <iostream>
#include <cmath>
#incude <fstream>



using namespace std;

int main()
{
double r[2];
double point[2];
double Dis;
int N;


ifstream fin;
fin.open("Robot_Point.dat");
fin>> r[0]>>r[1];
fin.close();

cout<<"Robots reference point is:  "<<r[0]<<" , "<<r[1]<<endl;

fin.open("Polygons.dat");
fin>>N;



int i=0;
while(i<N)
{
    fin>>point[0]<<point[1];

    Dis=sqrt(pow((r[0]-point[0]),2)-pow((r[1]-point[1]),2));

    i++;

    cout<<"Dis ="<<Dis<<endl;
}
fin.close();

return 0;

}

3 个答案:

答案 0 :(得分:2)

你有两个拼写错误:

#incude改为#include而将fin>>point[0]<<point[1];改为fin>>point[0]>>point[1];

编译器警告/错误不是最有启发性的(特别是在处理ostream& operator<<等模板时),但您将学会及时阅读它们。

答案 1 :(得分:0)

在这一行:

fin>>point[0]<<point[1];

你可能意味着:

fin>>point[0]>>point[1];

此外,您应该将#incude更改为#include

答案 2 :(得分:0)

这显然是错误的

fin>>point[0]<<point[1];

替换为

fin>>point[0]>>point[1];

这是一个关于Basic IO的简单教程

http://www.cplusplus.com/doc/tutorial/basic_io/