Answer to Question #180497 in C++ for Ayush

Question #180497

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


1
Expert's answer
2021-04-12T13:36:41-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS