Thread: Attach several ifstreams files into one?

  1. #1

    Attach several ifstreams files into one?

    Hello, I wanted to calc a checksum from several files. In stead of getting the checksum of each file I wanted to attach all files into one big file, and then calc the checksum of that. Can I do this with ifstreams?
    Thank you.

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    You mean morph several files into one?
    Yes, that's possible. Read one file at a time and write it to the new file:
    #include <fstream.h>
    const char* NewFileName = "NewFile.txt";
    const char* OldFileName[] = {"PartOne.txt",
    const int NrOfFiles = 3;
    int main()
       ofstream WriteFile;
       ifstream ReadFile;
       int Size;
       char* Buffer = NULL;
       //Open the file for writing, ios::out | ios::binary);
          return 0;
       //Loop though all files
       for(int i=0; i<NrOfFiles; i++)
          //Open the file
[i], ios::in | ios::nocreate | ios::binary);
             //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)
      , Size);
                WriteFile.write(Buffer, Size);
                delete[] Buffer;
                Buffer = NULL;
             //Close the file
       //Close the file and exit
       return 0;

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    Thank you very much.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Folding@Home Cboard team?
    By jverkoey in forum A Brief History of
    Replies: 398
    Last Post: 10-11-2005, 08:44 AM
  2. header and source files
    By gtriarhos in forum C Programming
    Replies: 3
    Last Post: 10-02-2005, 03:16 AM
  3. Batch file programming
    By year2038bug in forum Tech Board
    Replies: 10
    Last Post: 09-05-2005, 03:30 PM
  4. reinserting htm files into chm help files
    By verb in forum Windows Programming
    Replies: 0
    Last Post: 02-15-2002, 09:35 AM
  5. displaying text files, wierd thing :(
    By Gades in forum C Programming
    Replies: 2
    Last Post: 11-20-2001, 05:18 PM