I have an add filename function that saves the filenames to a text file like so:
Code:
outfile.open("database.txt", ios::app);
outfile << filename << endl;
outfile.close();
and retrieves the filenames from another function to manipulate them with
Code:
infile.open("database.txt");
while (!infile.eof())
{
infile.getline(file,80);
vfn.push_back(file);
}
infile.close();
This crashes at the last infile.open("database.txt") call because of where the cursor is positioned in the saved text file and I guess it tries to read the last line which doesn't have any text in it
Code:
TEXT FILE
filename
filename
filename
cursor position
If I manually save the file with the cursor position with the last end of line command removed, it works perfectly
Code:
TEXT FILE THIS WORKS
filename
filename
filenamecursor position
The problem is, once it's saved like that, when I return to my add file function I obviously have a little problem
Code:
TEXT FILE
filename
filename
filenameFILENAME //should not be here
cursor position
Basically, I just don't know how I can save my file in order to be able to retrieve it correctly.
Do I need to put " endl" at the end of each filename I save on the output?
If I don't, it is not only on one line so how do I retrieve only one filename at a time?
Any suggestions? Thanks in advance!!!