I am trying to work on an assignment that allows you to create an entry for a phone book, but there are a few things confusing me:
#include <string>
#include <iostream>
#include "entry.h"
using namespace std;
entry::entry()
{
p_fname = "";
p_lname = "";
p_phone = "";
}
entry::entry(std::string fname, std::string lname, std::string phone)
{
p_fname = fname;
p_lname = lname;
p_phone = phone;
}
/// sets fname to its parameter
void entry::set_fname(std::string fname)
{
p_fname = fname;
}
void entry::set_lname(std::string lname)
{
p_lname = lname;
}
void entry::set_phone(std::string phone)
{
p_phone = phone;
}
std::string entry::get_fname() const
{
std::string fname;
cout << "Enter First Name:" << endl;
cin >> fname;
return fname;
}
std::string entry::get_lname() const
{
std::string lname;
cout << "Enter Last Name:" << endl;
cin >> lname;
return lname;
}
std::string entry::get_phone() const
{
std::string phone;
cout << "Enter Phone Number:" << endl;
cin >> phone;
return phone;
}
And these are the headers of the last two functions that read an entry and print an entry, into and onto a stream, respectively. Can anyone tell me how to implement them?
/// reads from a stream into an entry. Needs to match up with operator<<
std::istream& operator>>(std::istream& in, entry&e);
/// 'prints' an entry onto a stream; hint: print each field, with a separator (a character that won't appear in the output otherwise, say : or ,)
std::ostream& operator<<(std::ostream& out, const entry&e);