// Передать в поток объект Employee...
ostream& operator<<(ostream& out, const Employee& emp) {
out << emp.firstName_ << endl;
out << emp.lastName_ << endl;
return(out);
}
// Считать из потока объект Employee
istream& operator>>(istream& in, Employee& emp) {
in >> emp.firstName_;
in >> emp.lastName_;
return(in);
}
int main() {
Employee emp;
string first = "William";
string last = "Shatner";
emp.setFirstName(first);
emp.setLastName(last);
ofstream out("tmp\\emp.txt");
if (!out) {
cerr << "Unable to open output file.\n";
exit(EXIT_FAILURE);
}
out << emp; // Записать Emp в файл
out.close();
ifstream in("tmp\\emp.txt");
if (!in) {
cerr << "Unable to open input file.\n";
exit(EXIT_FAILURE);
}