Video Coming Soon...
35: cp
Implement the first command line tool, cp.
//https://www.gnu.org/software/coreutils/manual/html_node/cp-invocation.html
#include <fmt/core.h>
#include <filesystem>
#include <fstream>
#include <iostream>
namespace fs = std::filesystem;
int main(int argc, char* argv[]) {
if(argc != 3) {
fmt::println("USAGE: cp <from_file> <to_file>");
return 1;
}
try {
fs::copy_file(argv[1], argv[2]);
} catch(fs::filesystem_error &e) {
fmt::println("failed to copy: {}", e.what());
}
}
Register for Learn C++ the Hard Way
Register to gain access to additional videos which demonstrate each exercise. Videos are priced to cover the cost of hosting.