I put this function in a loop and the first run throught the program works fine. On the second time throught the loop the "fin.fail()" fails and the program ends. I think the variable "in_file[40] is not resetting, but i am not sure. Can anyone help?
void get_file (ifstream &fin, ofstream &fout)
{
char in_file[40]= {}, out_file[40]= {};
cout << "What is the name of the file containing data to be analyzed?\n";
cin >> in_file;
fin.open(in_file);
if (fin.fail())
{
cout << "Input file failed.\n";
exit(1);
}
cout << "What is the name of the file where you would like to store data?\n";
cin >> out_file;
fout.open(out_file, ios::app);
if (fout.fail())
{
cout << "imput file failed.\n";
exit(1);
}
}
Awsome, that worked. What does that do? Any reason to put the fout.close() since it is working? I assume that I wrote it correctly, before the close()? Sorry for all the questions. Been trying to figure that out for about 8 hours....
Thanks, gave me my life back.