why is this writing the last line twice to the file
Code:
#include <iostream>
#include <fstream>
#include <vector>
#include <conio.h>
#include <stdlib.h>
using namespace std;
struct vertex {
float x;
float y;
float z;
};
vector<vertex> vertices;
int main(void) {
int numverts = 0;
int intmesh = 0; //THIS IS ADDED TO THE END OF THE OUTPUT FILE IN ORDER TO CREATE SEPARATE FILES FOR EACH MESH
char charmesh[20];
char outputfile[256];
char outfileext[256]; //THIS IS THE EXTENSION FOR THE OUTPUT FILE (.CUF)
char inputfile[256];
char type = 'v';
float x, y, z;
ifstream fin;
ofstream fout;
cout.setf(ios::fixed); //THIS PROBABLY ISN'T NECESSARY
cout << "Enter the name of an output file (without the extension, no numbers)" << endl;
cin.getline(outputfile, 256, '\n');
cout << "Enter which mesh number this is" << endl;
cin >> intmesh;
_itoa(intmesh, charmesh, 10); //CONVERT THE MESHNUMBER TO AN ALPHA TO ADD TO END OF FILENAME
strcat(outputfile, charmesh); //APPEND THE NUMBER TO THE END OF THE OUTPUT FILE
cin.ignore();
cout << "Now enter the name of the extension (with the period)" << endl;
cin.getline(outfileext, 256, '\n');
strcat(outputfile, outfileext);
cout << "Enter the name of the file to be read" << endl;
cin.getline(inputfile, 256, '\n');
fout.open(outputfile, ios::out);
fin.open(inputfile, ios::in);
if(fin.fail()){
cout << "Error, input file could not be opened" << endl;
return 0;
}
//READ IN THE CRAP FROM THE FILE
while(fin.good() && type == 'v') {
fin >> type;
if(type == 'v') {
fin >> x >> y >> z;
fout << x << " " << y << " " << z << endl;
}
}
fin.close();
fout.close();
return 0;
}