Can you check this code to see if it make sense? I declard the Triangle at global scope because it didn't seem to work inside the function
The triangle is:
struct Triangle{
float a,b,c,d,e,f,g,h,i;
};
This code is supposed to read in coordinates from a file until the end of the file is reached. I put a messagebox to signal when it gets to the end of the file so make sure it works, but even with a small number of coordinates it never reaches the end of the file
note I've tried using fin.good and !fin.eof in the while loop
Code:
void InputFileModule(void) {
vector<Triangle*> TriangleVector;
ofstream fout;
ifstream fin;
fout.open("Formatted coords.txt");
fin.open("Coordinates.txt");
if(fout.fail()) {
MessageBox(NULL, "Output file initialization failed", "ERROR", MB_OK);
return;
}
if(fin.fail()) {
MessageBox(NULL, "Input file initialization failed", "ERROR", MB_OK);
return;
}
int x = 0;
while(fin.good()) {
TriangleVector.push_back(new Triangle);
fin.ignore(2, NULL);
fin >> TriangleVector[x]->a;
fin >> TriangleVector[x]->b;
fin >> TriangleVector[x]->c;
fin.ignore(5, NULL);
fin >> TriangleVector[x]->d;
fin >> TriangleVector[x]->e;
fin >> TriangleVector[x]->f;
fin.ignore(5, NULL);
fin >> TriangleVector[x]->g;
fin >> TriangleVector[x]->h;
fin >> TriangleVector[x]->i;
fout << TriangleVector[x]->a << endl;
fout << TriangleVector[x]->b << endl;
fout << TriangleVector[x]->c << endl;
fout << TriangleVector[x]->d << endl;
fout << TriangleVector[x]->e << endl;
fout << TriangleVector[x]->f << endl;
fout << TriangleVector[x]->g << endl;
fout << TriangleVector[x]->h << endl;
fout << TriangleVector[x]->i << endl;
fin.seekg('\n');
fin.seekg(1);
x++;
}
MessageBox(NULL, "File Initialization Successful", "Success", MB_OK);
fin.close();
fout.close();
}
EDIT:
I tried putting
struct Triangle {
float a,b,c,d,e,f,g,h,i;
};
in the InputFileModule function and i get 20 errors !