Fri Nov 29 2019

Copy File

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:

We use cookies to improve your experience on our site and to show you personalised advertising. Please read our cookie policy and privacy policy.