How do I copy a file from one folder to another folder using C++?
相关问题
- Sorting 3 numbers without branching [closed]
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- thread_local variables initialization
- What uses more memory in c++? An 2 ints or 2 funct
This should be the minimal code required:
it glosses around some potentially complicated issues: error handling, filename character encodings... but could give you a start.
If you're willing to use the Boost C++ libraries, take a look at filesystem::copy_file().
Here's a previous question covering copy_file():
How to use copy_file in boost::filesystem?
With
std::filesystem::copy_file
from C++17:I've used
std::filesystem::path::filename
to retrieve the source filename without having to type it manually. However, withstd::filesystem::copy
you can omit passing the filename to the target path at all:Change the behaviour of both functions with
std::filesystem::copy_options
.The code below will copy all the file from one directory to another.
Its working code in C++