forked from pezy/CppPrimer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathex7_9.cpp
48 lines (37 loc) · 821 Bytes
/
ex7_9.cpp
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
46
47
48
//! @Alan
//!
//! Exercise 7.9:
//! Add operations to read and print Person objects to the code you wrote
//! for the exercises in § 7.1.2 (p. 260).
//!
#include <iostream>
#include <string>
struct Person
{
std::string name;
std::string address;
std::string getName(void) const {return this->name;}
std::string getAddress(void) const {return this->address;}
};
//!
//! \brief Exercise 7.9
//!
std::istream &read(std::istream &is, Person &p);
std::ostream &print(std::ostream &os, const Person &p);
int main()
{
Person p;
read(std::cin,p);
print(std::cout,p);
return 0;
}
std::ostream &print(std::ostream &os, const Person &p)
{
os<<p.getName()<<" "<<p.address;
return os;
}
std::istream &read(std::istream &is, Person &p)
{
is>>p.name>>p.address;
return is;
}