#include <iostream>
#include <string>
#include <fstream>
using namespace std;
class DIRECTORY{
private:
string name;
int phoneNumber;
public:
DIRECTORY(string na, int p){
name = na;
phoneNumber = p;
}
string getName(){
return name;
}
int getPhone(){
return phoneNumber;
}
void display(){
cout<<"The name is \t" <<getName()<<"\nThe phone number is\t"<<getPhone()<<endl;
}
};
int main(){
DIRECTORY d1("Johnson",902);
DIRECTORY d2("Victor",90223);
DIRECTORY d3("Sconfield",90212);
DIRECTORY d4("Harun",90223);
DIRECTORY d5("Benter",9022);
DIRECTORY d6("Alaba",9025);
ofstream fs("DIRECTORY.TXT", ios::out | ios::binary);
//Writing to a file
fs<<d1.getName()<<"\t"<<d1.getPhone()<<"\n";
fs<<d2.getName()<<"\t"<<d2.getPhone()<<"\n";
fs<<d3.getName()<<"\t"<<d3.getPhone()<<"\n";
fs<<d4.getName()<<"\t"<<d4.getPhone()<<"\n";
fs<<d5.getName()<<"\t"<<d5.getPhone()<<"\n";
fs.close();
char buffer[100];
//Reading and displaying from a file
ifstream file("DIRECTORY.TXT", ios::in | ios::binary);
char ch;
while(!file.eof()){
file.get(ch);
cout<<ch;
}
}
Comments
Leave a comment