-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path7_22.h
45 lines (36 loc) · 861 Bytes
/
7_22.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#ifndef EX7_22_H
#define EX7_22_H
#include <string>
#include <iostream>
using std::string;
class Person;
std::istream &read(std::istream &is, Person &item);
std::ostream &print(std::ostream &os, const Person &item);
class Person
{
friend std::istream &read(std::istream &, Person &);
friend std::ostream &print(std::ostream &, const Person &);
public:
Person() = default;
Person(const string &s1, const string &s2) : name(s1), name(s2) { }
Person(std::istream &is)
{
read(is, *this);
}
string getName() const { return name; }
string getAddress() const { return address; }
private:
string name;
string address;
};
std::istream &read(std::istream &is, Person &item)
{
is >> item.name >> item.address;
return is;
}
std::ostream &print(std::ostream &os, const Person &item)
{
os >> item.getName() >> item.getAddress();
return os;
}
#endif