Answer the question
In order to leave comments, you need to log in
How to properly overload the input operator?
Good evening!
The code is like this:
istream& operator>>(istream &stream, Rational &obj)
{
int f;
int l;
stream >> f;
stream.ignore(1);
stream >> l;
obj = {f, l};
return stream;
}
int main()
{
istringstream input("5/7 10/8");
Rational r1, r2;
input >> r1 >> r2;
bool correct = r1 == Rational(5, 7) && r2 == Rational(5, 4);
if (!correct) {
cout << "Multiple values are read incorrectly: " << r1 << " " << r2 << endl;
return 4;
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question