#include <fstream>
#include <iostream>
using namespace std;


char input_1[256]="1.wmv";
char output_1[256]="2.wmv";
char output_2[256]="3.wmv";



void Append()
{
    ofstream write(output_1,ios::binary|ios::app);
    ifstream read(output_2,ios::binary);
    read.seekg(0,ios::end);
    int size_=read.tellg();
    read.seekg(0,ios::beg);
    char* in=new char[size_];
    read.read(in,size_);
    write.write(in,size_);
    write.close();
    read.close();
}

void Split(){
    int size_;

    ifstream read(input_1,ios::in|ios::out|ios::binary);
    if(read.is_open())
    {
        read.seekg(0,ios::end);
        size_=read.tellg();
        const int half=size_/2;
        read.seekg(0,ios::beg);
        char* file_content_a=new char [half];
        char* file_content_b=new char [half];
        read.read(file_content_a,half);
        read.read(file_content_b,half);
        read.close();
        ofstream write_a(output_1,ios::binary);
        ofstream write_b(output_2,ios::binary);
        write_a.write(file_content_a,half);
        write_b.write(file_content_b,half);
        write_a.close();
        write_b.close();
    }
}


int main()
{
    cout << "Choose: \n"
            "1. Split\n"
            "2. Append\n";
    int c=2;
    cin >> c;

    switch(c){
        case 1:
             cout << "File to split: ";
             //cin >> input_1;
             cout << "Write to[1]: ";
             //cin >> output_1;
             cout << "Write to[2]: ";
             //cin >> output_2;
             Split();
             break;
        case 2:
             cout << "Append to: ";
             //cin >> output_1;
             cout << "Append from: ";
             //cin >> output_2;
             Append();
             break;
    }
    return 0;
}

This programs runs fine but in the end it fills the last file with garbage ?
Any suggestions please ?

which file are you talking about?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.