C++ Programming
Copy File
C plus plus example for copy file using file stream
By Geekboots
11/29/2019
0 views
copy-file.cppCPP
#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!cppcopy filefile stream