This code doesn't ever exit the loop and I'm not exactly sure why.
Code:
#include <iostream>
#include <fstream>
#include <vector>
#include <conio.h>
using namespace std;
struct Triangle {
float a, b, c, d, e, f, g, h, i;
};
vector<Triangle*> TriangleVector;
int main(void) {
ofstream fout;
ifstream fin;
fout.open("Formatted coords.txt");
fin.open("Coordinates.txt");
if(fout.fail()) {
cout << "Could not load coordinates" << endl;
cout << "Hit a key to escape" << endl;
getch();
return 0;
}
if(fin.fail()) {
cout << "Could not load coordinates" << endl;
cout << "Hit a key to escape" << endl;
getch();
return 0;
}
streampos Location = fin.tellg();
int x = 0;
while(!fin.eof()) {
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);
cout << TriangleVector[x]->a << endl;
cout << TriangleVector[x]->b << endl;
cout << TriangleVector[x]->c << endl;
cout << TriangleVector[x]->d << endl;
cout << TriangleVector[x]->e << endl;
cout << TriangleVector[x]->f << endl;
cout << TriangleVector[x]->g << endl;
cout << TriangleVector[x]->h << endl;
cout << TriangleVector[x]->i << endl;
getch();
x++;
}
cout << "You have reached the end of the file" << endl;
getch();
fin.close();
fout.close();
cout << "Hit a key to escape" << endl;
getch();
return 0;
}
EDIT:
When I take out the fin.seeg(1) it exits the loop but it only reads the first line then the rest is jibberish and I'm not sure why
What it is doing is reading the same line of the text file over and over agqin inst4ead of actually going to the next line and reading from there.