c++ - 如何在 C++ 中使 .Exe 复制自身?

标签 c++ exe

我是 C++ 新手,我希望我的应用程序在执行时能够 self 复制一次或两次。我在这个论坛上搜索过这个主题,但没有运气。所以我希望我没有挖掘已经讨论过的东西。到目前为止我得到的代码如下,我只是在尝试并尝试看看我可以在 C++ 中做哪些不同的事情 - 我正在制作的程序没有实际用途。 到目前为止我得到的代码如下。

#include <iostream.h>
#include <stdio.h>   
#include <string.h>
#include <stdlib.h>
#include <conio.h>
#include <windows.h>
#include <stdlib.h>
#include <fstream.h>

void main()

{
    int id;
    cout << "Hello\n";
    cin >> id;

    cout << "Testing" << id << endl;

 int i=0;
 do
 {
   i++;
   fstream feck ("lucinada.doc", fstream::in | fstream::out);
   feck << "testing";
24
 }while(i<100);


 int j=0;

 do

 {

   j++;

   fstream feck ("ludacris.doc", fstream::in | fstream::out);

   feck << "testing";

 }while(j<100);



 int k=2;
 do
 {

   k++;

   fstream feck ("400l.doc", fstream::in | fstream::out);

   feck << "testing";}while(k<100);}

如何将我的应用程序 .exe 复制到多个路径。

提前致谢

最佳答案

使用 GetModuleFileName 获取可执行文件的路径然后使用 CopyFile 复制它.

当然,这个解决方案只能在 Windows 下工作,但就文件系统操作而言,您始终必须为每个操作系统实现它们(除非您使用 boost::filesystem 之类的东西)。

关于c++ - 如何在 C++ 中使 .Exe 复制自身?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37434012/

相关文章:

c - 定义一个C程序编译后要修改的地址

c++ - Boost ASIO 可能会影响同一台机器上其他程序的性能

c++ - 更改 .exe 文件版本(来自 C++ 项目)

c++ - 在 C++ 中调整卷文件的长度和宽度

c++ - 检查失败 : 1 == NumElements() (1 vs. 1792)在 Tensorflow C++ 中必须有一个元素张量

c++ - 将 list 嵌入到 exe 文件

linux - Linux 中 t32.exe 文件的用途是什么?

c++ - 如何生成包含可通过脚本轻松修改的数据的 exe

c++ - C++ 中的复活节星期天

c++ - 将单个字符转换为 std::string prepends\x01