Fri Nov 29 2019
Copy File
C++ Programming922 views
File Name: copy-file.cpp
#include<iostream>
#include<fstream>
using namespace std;
int main() {
int size = 20;
char line[size];
/* Connect 'data.txt' to 'wfile' */
ifstream rfile("data.txt");
ofstream wfile("new_data.txt");
cout << "Copping data from one file to another..." << endl;
/* Check end of file */
while(rfile) {
/* Read a line */
rfile.getline(line,size);
/* Write the line */
wfile << line << endl;
}
cout << "File Copied!" << endl;
/* Disconnect files from 'wfile' and 'rfile' */
rfile.close();
wfile.close();
return 0;
}
/* Output */
Copping data from one file to another...
File Copied!
Reference:
Input/Output in C++
Author:Geekboots