You mean morph several files into one?
Yes, that's possible. Read one file at a time and write it to the new file:
Code:
#include <fstream.h>
const char* NewFileName = "NewFile.txt";
const char* OldFileName[] = {"PartOne.txt",
"PartTwo.txt",
"PartThree.txt"};
const int NrOfFiles = 3;
int main()
{
//Data
ofstream WriteFile;
ifstream ReadFile;
int Size;
char* Buffer = NULL;
//Open the file for writing
WriteFile.open(NewFileName, ios::out | ios::binary);
if(WriteFile.fail())
{
return 0;
}
//Loop though all files
for(int i=0; i<NrOfFiles; i++)
{
//Open the file
ReadFile.open(OldFileName[i], ios::in | ios::nocreate | ios::binary);
if(!ReadFile.fail())
{
//Get the size of the file
ReadFile.seekg(0, ios::end);
Size = ReadFile.tellg();
ReadFile.seekg(0, ios::beg);
//Read data into a buffer, then write it to a file
Buffer = new char[Size];
if(Buffer != NULL)
{
ReadFile.read(Buffer, Size);
WriteFile.write(Buffer, Size);
delete[] Buffer;
Buffer = NULL;
}
//Close the file
ReadFile.close();
}
}
//Close the file and exit
WriteFile.close();
return 0;
}