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 B R Ambedkar National Institute of Technology
#include<iostream>
#include<fstream>
#include<string.h>
using namespace std;
int main()
{
char name[100];
ofstream out("college.txt");
for(int i=1;i<=3;i++)
{
cout<<"Enter college name "<<i<<": ";
gets(name);
out<<name<<"\n";
}
out.close();
out.open("university.txt");
ifstream in("college.txt");
while(in)
{
in.getline(name,99);
out<<name<<"\n";
}
out.close();
in.close();
in.open("university.txt");
cout<<"\nColleges name from university.txt file:\n"<<endl;
while(in)
{
in.getline(name,99);
cout<<name<<"\n";
}
return 0;
}
Comments
Leave a comment