'Copy file in C++' program is given below.
Copies content of file 'a' to file 'b'.
#include <iostream>
#include <fstream>
using namespace std;
int main(){
char line[100];
ifstream is("a.txt");
ofstream os("b.txt");
if (is.is_open()){
while (!is.eof()){
is.getline(line,100,'\n');
os << line << endl;
}
}
else{
cout << "a.txt couldn't be opened. Creat and write something in a.txt, and try again." << endl;
}
return 0;
No comments:
Post a Comment