LIVE Course for free

Rated by 1 million+ students
Get app now
0 votes
2.5k views
in Computer by (69.0k points)

Write a program that appends the contents of one file to another. Have the program take the filenames from the user.

1 Answer

+1 vote
by (60.8k points)
selected by
 
Best answer

#include <iostream.h>

#include<conio.h>

#include<fstream.h>

#include<stdlib.h>

void main() {

ofstream outfile;

ifstream infile;

char fname1[10],fname2[20];

char ch,uch;

clrscr( );

cout<<"Enter a file name from where to append ";

cin>> fname1;

cout<<"Enter the file name where to append";

cin>>fname2;

infile.open(fname1);

if( infile.fail())

{

cout<< " No such a file Exit";

getch();

exit(1);

}

outfile.open(fname2,ios::app);

while( !infile.eof())

{

ch = (char)infile.get();

outfile.put(ch);

}

infile.close( );

outfile.close( );

getch( );

}

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...