Appending Binary file....

I was trying to append two binary file specially EXE

so I coded this

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include<iostream>
#include<fstream>
using namespace std;

main() {
    char ch;
    char first[19], last[19];
    cin>>first;
    cin>>last;
    ofstream out(first, ios::out | ios::app | ios::binary);
    ifstream in(last, ios::in | ios::binary);

    while(in) {
        in.get(ch);
        if(in)	out.put(ch);
    }
}


This Code Append file successfully but when I Execute the appended Exe, only the first EXE will execute can anyone explain why and how to fix it so that successively both of exe will execute .
Last edited on
The way the file is read by the system makes a difference too...

What exactly is it you are trying to do with your two executables?
I only want to run both EXE successively.
It doesn't work that way, unless you have written first EXE yourself, so you know the offset and it contains special code to extract and execute the second EXE. This tehnique is used by self-extracting archivers and some installers.

Are you trying to write a virus os something ?
Nope I'm not writing a virus or something it is just my curiosity.

maybe if i delete 4 b-5 bytes from first exe than it will work

Maybe but let me test

Thanks @modoran and Duoas for your support
It won't matter what you do to it -- it won't work. (You'll just wind up breaking it.)

You could just put both EXEs into the same folder, along with a batch file that starts them both:

1
2
3
::start both exes at the same time batch file
start program1.exe
start program2.exe

To start both, just double-click the batch file.

The only drawback to this approach is that you might see a console window pop up for a second.

(If you use the wscript you can avoid that, too.)
Topic archived. No new replies allowed.