简体   繁体   English

复制文件在 C++ 中没有任何作用

[英]Copying file doesn't do anything in C++

I'm a beginner in C++ and I'm trying to make a file manager used with commands.我是 C++ 的初学者,我正在尝试制作一个与命令一起使用的文件管理器。 Everything was good except for the copy function.一切都很好,除了复制功能。

#include <stdlib.h>
int main(int argc, char * argv[])
{
    system(*"copy \"" + argv[0] + *"\" \"C:/Users/doubl/Desktop\"");
}

There isn't an error when compiling and running, but it never actually transfers anything.编译和运行时没有错误,但它实际上从未传输任何东西。

Is there a better way to do this?有一个更好的方法吗? if not what am I doing wrong here?如果不是我在这里做错了什么?

A possible way to copy files in C++ is to learn then use some existing C++ library or framework, like Qt or POCO .在 C++ 中复制文件的一种可能方法是学习然后使用一些现有的 C++ 库或框架,如QtPOCO

Another way is to use C++ std::string -s, documented here to build your command line.另一种方法是使用此处记录的 C++ std::string -s 来构建您的命令行。

Newer C++ standards have std::filesystem documented here .较新的 C++ 标准在此处记录了std::filesystem

Of course, you will spend days in reading documentation.当然,您将花费数天时间阅读文档。

My recommendation is to read the documentation of your C++ compiler (eg GCC , that you might invoke as g++ -Wall -Wextra -g - all warnings and debug info).我的建议是阅读您的 C++ 编译器的文档(例如GCC ,您可能会调用它g++ -Wall -Wextra -g - 所有警告和调试信息)。 Then read the documentation of your debugger (eg GDB ).然后阅读调试器的文档(例如GDB )。

You probably also want to read the documentation of your version control system (eg git ).您可能还想阅读版本控制系统的文档(例如git )。

Notice that your code (even improved a bit) won't work on my computers (they all run Linux), since copy (as a program) does not exist on them.请注意,您的代码(甚至改进了一点)将无法在我的计算机上运行(它们都运行 Linux),因为它们上不存在copy (作为程序)。 The near equivalent program is called /bin/cp part of GNU coreutils .几乎等效的程序称为 GNU coreutils/bin/cp部分。

I heard that copy is a Windows specific program.我听说那个copy是一个 Windows 特定的程序。 It existed on MSDOS.它存在于 MSDOS 上。

At last, some computers (eg RaspberryPi ) might be programmable in C++ and not even have any files.最后,一些计算机(例如RaspberryPi )可能是用 C++ 编程的,甚至没有任何文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM