forked from Mooophy/Cpp-Primer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ex7_50.h
46 lines (37 loc) · 1015 Bytes
/
ex7_50.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
//
// ex7_50.cpp
// Exercise 7.50
//
// Created by pezy on 11/24/14.
// Copyright (c) 2014 pezy. All rights reserved.
//
// @See ex7_22.h
// @Add constructors should be explicit
#ifndef CP5_ex7_50_h
#define CP5_ex7_50_h
#include <string>
#include <iostream>
struct Person {
friend std::istream &read(std::istream &is, Person &person);
friend std::ostream &print(std::ostream &os, const Person &person);
public:
Person() = default;
Person(const std::string sname, const std::string saddr):name(sname), address(saddr){}
explicit Person(std::istream &is){read(is, *this);}
std::string getName() const { return name; }
std::string getAddress() const { return address; }
private:
std::string name;
std::string address;
};
std::istream &read(std::istream &is, Person &person)
{
is >> person.name >> person.address;
return is;
}
std::ostream &print(std::ostream &os, const Person &person)
{
os << person.name << " " << person.address;
return os;
}
#endif