-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIO_OperatorOverloading.cpp
More file actions
40 lines (28 loc) · 880 Bytes
/
IO_OperatorOverloading.cpp
File metadata and controls
40 lines (28 loc) · 880 Bytes
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
#include <iostream>
class Coordinate
{
private:
int m_x, m_y, m_z;
public:
Coordinate(int x, int y, int z) : m_x { x }, m_y { y }, m_z { z } {}
friend std::ostream& operator<<(std::ostream &output, const Coordinate &coordinate);
friend std::istream& operator>>(std::istream &input, Coordinate &coordinate);
};
std::ostream& operator<<(std::ostream &output, const Coordinate &coordinate)
{
output << coordinate.m_x << ";" << coordinate.m_y << ";" << coordinate.m_z;
return output;
}
std::istream& operator>>(std::istream &input, Coordinate &coordinate)
{
input >> coordinate.m_x >> coordinate.m_y >> coordinate.m_z;
return input;
}
int main()
{
Coordinate coord(1337, 7331, 3713);
std::cout << "Coordinate: " << coord << std::endl;
std::cin >> coord;
std::cout << "New coordinate: " << coord << std::endl;
return 0;
}