Week 13b solution               
13 b) Write a C++ program that accepts two file 
names and produces new file that is the contents 
of the first file followed by the contents of the
second; that is, the program concatenates the two files.
file1.txt:
hello
Welcome to c++ programming
file2.txt:
happy coding............
Program:
#include<iostream>
#include<fstream>
using namespace std;
int main()
{
 ifstream file1("file1.txt");
 ifstream file2("file2.txt");
 ofstream file("new.txt") ;
 file<<file1.rdbuf()<<"\n"<<file2.rdbuf();
 cout<<"After conacatenation of two files \n";
 file.close();
 ifstream f("new.txt");
 cout<<f.rdbuf();
 f.close();
 return 0;
}
Output:
After conacatenation of two files
hello
Welcome to c++ programming
happy coding............
 
 
No comments:
Post a Comment