/* Point_stdin.cpp - Read a "Points" data structure from a file, and then read points from standard input. For each point, print the minimum distance to a point in Points. James S. Plank CS494/594 Lecture notes. Fri May 15 15:28:39 EDT 2020 */ #include "points.hpp" #include #include #include #include #include #include #include using namespace std; typedef std::runtime_error SRE; int main(int argc, char **argv) { Points points; ifstream fin; vector x; double d; string line; istringstream ss; if (argc != 2) { fprintf(stderr, "usage: points_stdin point-file\n"); exit(1); } /* Read the points from the file given on the command line. */ fin.open(argv[1]); if (fin.fail()) { perror(argv[1]); exit(1); } try { points.Read(fin); } catch (const SRE &e) { fprintf(stderr, "Error reading %s:\n%s\n", argv[1], e.what()); exit(1); } /* For each line, read a point, and print Min_Distance() called on the point. */ while (cin >> line) { try { x.clear(); ss.clear(); ss.str(line); while (ss >> d) x.push_back(d); if (x.size() != 0) printf("%lg\n", points.Min_Distance(x)); } catch (const SRE &e) { printf("%s\n", e.what()); } } return 0; }