Question
The istream operator here is being overloaded and im not sure what the TODO mean. I looked up what peek does but i dont know
The istream operator here is being overloaded and im not sure what the TODO mean. I looked up what peek does but i dont know how to use it in this situation. Please help
// TODO: Make this read integer values if no '/' is given as a separator. // You may assume that there is no space between the numerator and the // slash. Hint, find and read the reference documentation for istream::peek(). std::istream& operator>>(std::istream& is, Rational& r) { int p, q; char c; is >> p >> c >> q; if (!is) return is;
// Require that the divider to be a '/'. if (c != '/') { is.setstate(std::ios::failbit); return is; }
// Make sure that we didn't read p/0. if (q == 0) { is.setstate(std::ios::failbit); return is; }
r = Rational(p, q); return is; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started