#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main(){
const string FILE_NAME_COLLAGE="college.txt";
const string FILE_NAME_UNIVERSITY="university.txt";
ofstream collegeFile(FILE_NAME_COLLAGE, ios::out);
//Read names of 3 colleges from console
for(int i=0; i<3; ++i)
{
string collegeName;
cout<<"Enter college name: ";
getline(cin, collegeName);
//save college name into the file "college.txt"
collegeFile << collegeName<<"\n";
}
collegeFile.close();
ifstream collegeFileReading(FILE_NAME_COLLAGE);
//Copy contents of "college.txt" in another file "university.txt".
if(!collegeFileReading){
cerr << "Error: the file "<<FILE_NAME_COLLAGE<<" does not exist.\n";
return 1;
}
string line;
ofstream universityFile(FILE_NAME_UNIVERSITY, ios::out);
while(getline(collegeFileReading, line)){
universityFile << line<<"\n";
}
collegeFileReading.close();
universityFile.close();
ifstream universityFileReading(FILE_NAME_UNIVERSITY);
// open the "university.txt" file and display the following (underlined) characters on console using file.
if(!universityFileReading){
cerr << "Error: the file "<<FILE_NAME_UNIVERSITY<<" does not exist.\n";
return 1;
}
cout<<"\n";
while(getline(universityFileReading, line)){
cout<< line<<"\n";
cout<<"________________________________________________\n";
}
universityFileReading.close();
system("pause");
return 0;
}
Comments
Leave a comment