'Paste contents of .exe into my code to create copies using C++

I am trying to use C++ to create as many copies of a .exe as I need. The original .exe won't be accessible, so I want to paste its code into the program before I compile it.

#include <fstream>
#include <iostream>
#include <string>

int main()
{

    for (int i = 1; i <= 5; ++i) {
        std::ofstream fout;
        fout.open("test-" +
                   std::to_string(i) + ".exe");

        if (!fout) {
            std::cerr << "Error\n";
            return 1;
        }
        fout << //"contents of exe";
        fout.close();
    }
}

I want the already compiled .exe code to be pasted where the fout << //"contents of exe"; is, but I can't figure out how to do it.

Any help would be appreciated, tysm!

c++


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source