// Code derived from Stroustrup's PPP2 book// § 10.4 Opening a file// -and beginning on p 350#include<fstream>#include<iomanip>#include<iostream>#include<stdexcept>#include<string>#include<vector>usingnamespacestd;voiderror(conststrings){throwruntime_error(s);}voiderror(conststrings1,conststrings2){error(s1+s2);}//------------------------------------------------------------------------------structPoint{intx;inty;friendistream&operator>>(istream&ist,Point&p){chara,b,c;if((ist>>a>>p.x>>b>>p.y>>c)&&!(a=='('&&b==','&&c==')'))error("Invalid format");returnist;}friendostream&operator<<(ostream&ost,constPoint&p){returnost<<'('<<setw(2)<<p.x<<','<<setw(2)<<p.y<<')';}};intmain()try{cout<<"Please enter input file name (eg, points.txt ): ";stringiname;cin>>iname;ifstreamist{iname};// ist is an input stream for the file named in inameif(!ist)error("can't open input file ",iname);vector<Point>points;for(Pointp;ist>>p;)points.push_back(p);for(auto&p:points)cout<<p<<'\n';}catch(exception&e){cerr<<"error: "<<e.what()<<'\n';return1;}catch(...){cerr<<"Oops: unknown exception!\n";return2;}