Skip to content

Instantly share code, notes, and snippets.

@marianbrunet
Created May 25, 2021 18:22
Show Gist options
  • Save marianbrunet/fdd1cf0bb92ccdff6b1d50df2e78e024 to your computer and use it in GitHub Desktop.
Save marianbrunet/fdd1cf0bb92ccdff6b1d50df2e78e024 to your computer and use it in GitHub Desktop.
Copy file from one directory to another - cpp
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <experimental/filesystem>
namespace fs = std::experimental::filesystem;
int main()
{
fs::create_directories("sandbox/dir/subdir");
std::ofstream("sandbox/file1.txt").put('a');
fs::copy("sandbox/file1.txt", "sandbox/file2.txt");
}
// compile with:
// g++ -std=c++17 copy_file.cpp -o copyfile -lstdc++f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment