You asked about
fstream
specifically, so I'll stick to that. I haven't looked at the rest of your code in any detail, because something caught my eye straight away.
In
main()
, you write
if (!inFile.fail())
{
cout << "Error in opening file." << endl;
exit(1);
}
If everything has gone well to this point, this will always print the error message and exit! The reason is that you've conflated two things:
if(!infile)
checks for an error, and so does
if(infile.fail())
but
if(!infile.fail())
means "If there
isn't an error, then...