I want to make copies of an executable file itself multiple times.
I tried the following code:
#include <fstream>
#include <string>
int main() {
std::ifstream from("main.exe", std::ios::binary);
auto buf { from.rdbuf() };
for(int x { 0 }; x <= 10; ++x) {
std::string name { "main" + std::to_string(x) + ".exe" };
std::ofstream out(name, std::ios::binary);
out << buf;
out.close();
}
from.close();
return 0;
}
但是,它没有像我所期望的那样做工作(它没有重复复制可执行的工作)。 见以下屏幕上的规模一栏:
我如何解决这一问题?