Write a C++ program to create a new file named "college.txt" to store list of colleges under Punjab university Read names of 3 colleges (consider input given below )from console and store it in "college.txt". Further copy contents of "college.txt" in another file "university.txt". Now open the "university.txt" file and display the following (underlined) characters on console using file.
manipulation functions
Input:
Lovely Professional University
Thapar Institute of Engineering and Technology
Dr BR Ambedkar National Institute of Technology
#include<iostream>
#include <bits/stdc++.h>
using namespace std;
int main(){
string line1, line2, line3,tString;
fstream fileName;
ofstream outputfile;
fileName.open("college.txt",ios::out);
if(!fileName){
cout<<"There is some error in creating the file"<<endl;
return 0;
}
cout<<"file created successfully"<<endl;
cout<<"Enter name of first college:"<<endl;
cin>>line1;
fileName<<line1<<endl;
cout<<"Enter name of second college:"<<endl;
cin>>line2;
fileName<<line2<<endl;
cout<<"Enter name of third college:"<<endl;
cin>>line3;
fileName<<line3<<endl;
outputfile.open("university.txt");
ifstream input{"college.txt"};
ofstream outputfile1{"university.txt"};
if (input && outputfile1)
{
while (getline(input, tString))
{
outputfile1<<tString<< "\n";
}
cout << "\n\n Source File Date Successfully Copied to Destination File...!!!";
}
else
{
cout << "File Cannot Open...!!!";
}
return 0;
}
Comments
Leave a comment