I 'm having trouble with a part of my program that reads in points (coordinates) from a file and then prints them out. It's spitting out garbage. I think it has to do with the printing rather than the scanning. I am new to c++.
Here's a snippit from my main.cpp:
Code:
ifstream isIn("points.txt", ios::in);
i=0;
Point2D[i].setX(isIn, dX); //scanning in first X coordinate
Point2D[i].setY(isIn, dY); //scanning in first Y coordinate
i++;
while(!isIn.eof() && i < MAXNUMPTS)
{
Point2D[i].setX(isIn, dX); //scanning the remaining X coordinates
Point2D[i].setY(isIn, dY); //scanning the remaining Y coordinates
i++;
}
cout <<"Here are your coordinates:" <<endl;
for (j=0; j<(i+1); j++)
{
cout <<"Point "<< j+1;
dX = Point2D[j].getX(); //Printing all X coordinates
cout <<dX;
dY = Point2D[j].getY(); //Printing all Y coordinates
cout <<dY;
cout <<")\n";
}
And here's a snippit from another .cpp file that's included (function implimentations):
Code:
void Point::setX(ifstream& isIn, double dX)
{
isIn >> dX;
}
double Point::getX()
{
return(dX);
}
void Point::setY(ifstream& isIn, double dY)
{
isIn >> dY;
}
double Point::getY()
{
return(dY);
}