Try to use getline instead of >> when getting the filenames. Also, always check wether your File.open() succeeds or fails. I guess that this is why your program crashes (no need for clear, you can reopen a file assuming you close it first, which you did).
The code below works just fine.
Code:
#include <fstream.h>
int main()
{
//Data
char Buffer;
char FileName[256];
ifstream FileList;
ifstream File;
ofstream NewFile;
//Attempt to open the list of filenames
FileList.open("FileList.txt", ios::in);
if(FileList.fail())
{
return 0;
}
//Attempt to open the output file
NewFile.open("Result.txt", ios::out);
if(NewFile.fail())
{
FileList.close();
return 0;
}
//Loops though all filenames in the list
while(!FileList.eof())
{
//Open the files in the list one by one
FileList.getline(FileName, 255);
File.open(FileName, ios::in);
if(!File.fail())
{
while(!File.eof())
{
//Read one byte
File.get(Buffer);
//Filter out EOF character
//(There must be a better way than this...)
if(Buffer != 'ÿ')
{
NewFile << Buffer;
}
}
//Add a newline (formating purposes)
NewFile << endl;
File.close();
}
}
//Exit
FileList.close();
NewFile.close();
return 0;
}
If someone knows a better way to remove the EOF character at the end of the file, plz tell :).