Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <string>
- #include <iostream>
- void mv(std::string const &fname_from, std::string const &fname_to) {
- std::ifstream from(fname_from, std::ios_base::in | std::ios_base::binary); // open file for reading
- if (!from) {
- std::cerr << "Can't open " << fname_from << " for reading.\n";
- throw 1;
- }
- std::ofstream to(fname_to, std::ios_base::out | std::ios_base::trunc | std::ios_base::binary);
- if (!to) {
- std::cerr << "Can't open " << fname_to << " for writing.\n";
- throw 1;
- }
- char c;
- while (from.get(c))
- if (!to.put(c)) {
- std::cerr << "Error writing to " << fname_to << '\n';
- throw 1;
- }
- }
- int main() {
- mv ("a.exe", "b.exe");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement