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 Technolog
#include <iostream>
#include <fstream>
#include <string>
#define under "\033[4m"
#define notunder "\033[0m"
using namespace std;
int main()
{
string line;
ofstream outf ("college.txt");
if (!outf)
{
cout << "File I / O error\n";
return 1;
}
for (int i = 0; i < 3; i++)
{
cout << "Type in the name of the college and hit Enter :";
getline(cin, line);
outf << line << "\n";
}
outf.close();
ofstream outf1 ("university.txt");
if (!outf1)
{
cout << "File I / O error\n";
return 1;
}
ifstream inf("college.txt");
if (!inf)
{
cout << "File I / O error\n";
return 1;
}
while (inf)
{
getline(inf, line);
outf1<< line << "\n";
}
inf.close();
outf1.close();
ifstream inf1("university.txt");
if (!inf1)
{
cout << "File I / O error\n";
return 1;
}
while (inf1)
{
getline(inf1, line);
cout << under << line << notunder << endl;
}
inf1.close();
system("pause");
return 0;
}
Comments
Leave a comment