-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInputOutputOperator.cpp
More file actions
84 lines (67 loc) · 1.68 KB
/
InputOutputOperator.cpp
File metadata and controls
84 lines (67 loc) · 1.68 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/**
* \file InputOutputOperator.cpp
* \brief
*
* \review
*/
#include <StdStream/StdStream.h>
#include <StdTest/StdTest.h>
#include <Stl.h>
//--------------------------------------------------------------------------------------------------
class Point
{
public:
Point(
double x = 0.0,
double y = 0.0,
double z = 0.0
) :
m_x(x),
m_y(y),
m_z(z)
{
}
friend
std::ostream &operator << (std::ostream &out, const Point &point);
friend
std::istream &operator >> (std::istream &in, Point &point);
private:
double m_x{}, m_y{}, m_z{};
};
//--------------------------------------------------------------------------------------------------
// If you try to return std::ostream by value, you’ll get a compiler error.
// This happens because std::ostream specifically disallows being copied.
std::ostream &
operator<< (std::ostream &out, const Point &point)
{
out << "Point(" << point.m_x << ", " << point.m_y << ", " << point.m_z << ")";
return out;
}
//--------------------------------------------------------------------------------------------------
std::istream &
operator >> (std::istream &in, Point &point)
{
in >> point.m_x;
in >> point.m_y;
in >> point.m_z;
return in;
}
//--------------------------------------------------------------------------------------------------
int main()
{
Point p1(1.0, 2.0, 3.0);
Point p2(4.0, 5.0, 6.0);
std::cout << p1 << " " << p2 << std::endl;
Point p3;
std::cin >> p3;
std::cout << "You entered " << p3 << std::endl;
return EXIT_SUCCESS;
}
//--------------------------------------------------------------------------------------------------
#if OUTPUT
Point(1, 2, 3) Point(4, 5, 6)
1
2
3333
You entered Point(1, 2, 3333)
#endif