Using the solution to this thread, I have a general idea on how to read line-by-line in a text file. My issue arises on how to populate that data into my phonebook, a pointer to an array of objects.
This is what my text file outputs.
Albert, Fred
4541231234
8888 Avenue Drive
Doe, John
6191231234
1234 State Street
Smith, Mike
8791231234
0987 Drive Avenue
What I want to do, is to parse through each line and use whatever information it takes to populate my Phone Book, which is defined as.
class AddressBook
{
private:
Contact* phoneBook[maxSize]; //array of contact pointers
...etc
}
class Contact
{
public:
Contact();
std::string firstName;
std::string lastName;
std::string name; //lName + fName
std::string phoneNumber;
std::string address;
};
I can get it to read line by line, at least I think, but I don't know where to start on how I can get it to recognize if it's a first name, last name, phone number, or address since they're all strings.
void AddressBook::writeToFile(Contact * phoneBook[])
{
std::string line;
std::ifstream myFile("fileName.txt");
if (myFile.is_open())
{
while (getline(myFile, line))
{
//do something
}
myFile.close();
}
}