forked from cpp-tutor/learnmoderncpp-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path08-point2.cpp
More file actions
39 lines (35 loc) · 781 Bytes
/
08-point2.cpp
File metadata and controls
39 lines (35 loc) · 781 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
// 08-point2.cpp : read Points from input stream
#include <iostream>
using namespace std;
struct Point {
int x{}, y{};
};
istream& operator>> (istream& is, Point& p) {
char a{}, b{}, c{};
int px, py;
is >> a >> px >> b >> py >> c;
if (is.good()) {
if (a == '(' && b == ',' && c == ')') {
p.x = px;
p.y = py;
}
else {
is.setstate(ios_base::failbit);
}
}
return is;
}
int main() {
cout << "Please enter Points, in the form \'(2,-3)\'\n";
Point p;
while (!cin.eof()) {
cin >> p;
if (cin.good()) {
cout << "Point read successfully!\n";
}
else {
cout << "Error in input!\n";
cin.clear();
}
}
}