Hi, I have been studying the C++ fundamentals for about a year now... off and on... and I just recently started again.
Currently, before I stopped reading on C++ I wrote a simple project that was a class test type program that used my personal Phonebook as a class, and each person in my phonebook as the objects.
Now, after completing this successfully, I wanted to make a program that either reads in the data file "Phonebook.txt" from the projects directory to display the current entries in the phonebook, or if there is no file there, be able to write a formatted data file with entries that are created in the program. My brain hasn't been focused recently....haha
here is the code so far... I dont have all the functions that I will be using... I just want to know if I am handling a file correctly... and if there isnt a file... if i am creating it correctly.
if i am doing this incorrectly... please let me know... i havnt even finished the handle file function cause im stuck...Code:#include <fstream.h>
#include "PBEntry.h"
const string UniversalFileName = "PhoneBook.txt";
void WriteEntries(PBEntry *Entry, ofstream *oFile)
{
oFile<<"\t\tListing:\t\t"<<Entry.getNum()<<endl;
oFile<<"\t\tName:\t\t\t"<<Entry.getName()<<endl;
oFile<<"\t\tHome Phone:\t\t"<<Entry.getHPhone()<<endl;
oFile<<"\t\tCell Phone:\t\t"<<Entry.getCPhone()<<endl;
oFile<<"\t\tAddress:\t\t"<<Entry.getAddress()<<endl<<endl;
}
void HandleFile()
{
ifstream *File;
File.open(UniversalFileName);
if(!File)
{
cout<<"ERROR: Data File \"PhoneBook.txt\" could not be opened or found!"<<endl;
cout<<"Create a new file named Phonebook.txt?(Y or N): ";
char answer;
cin>>answer;
cout<<"\n";
if(answer=='y' || answer=='Y')
{
ofstream nFile(UniversalFileName);
if(!nFile.is_open())
{
cout<<"File could not be created! Press Enter to exit the program...."<<endl;
cint.get();
return 0;
}
nFile.close(); // File Created....
}
else if(answer=='n' || answer=='N')
{
cout<<"\nThis program can go no further without a file. Press Enter to end the program..."<<endl;
cin.get();
return 0;
}
}
string *fEntryNum;
string *fEntryName;
string *fEntryHPhone;
string *fEntryCPhone;
string *fEntryAddress;
while(!File.eof())
{
getline(File, &fEntryNum, '\t');
getline(File, &fEntryName, '\t');
getline(File, &fEntryHPhone, '\t');
getline(File, &fEntryCPhone, '\t');
getline(File, &fEntryAddress);
}
int main()
{
}