Question: im writing in c++ and using codeblocks and am getting this error 1test_rational.cpp|111|error: cannot bind 'std::istream {aka std::basic_istream }' lvalue to 'std::basic_istream &&'| the code
im writing in c++ and using codeblocks and am getting this error
1\test_rational.cpp|111|error: cannot bind 'std::istream {aka std::basic_istream
the code in question std::cin >> r1 >> op >> r2; It should be noted i didnt write the code, it was given by instructor.
void rc() { // Determine if input is coming from a terminal. bool term = isatty(0);
// This will continue reading until it reaches the end-of-input. // If you are using this interactively, type crtl-d to send the // end of input character to the terminal. while (std::cin) { Rational r1; Rational r2; std::string op;
if (term) std::cout << "> ";
std::cin >> r1 >> op >> r2; if (!std::cin) break;
The istream operator is overwritten and this is the code for that
std::istream& operator>>(std::istream& is, Rational& r) { if (!is) return is; int p, q; char c; is >> p;
c = is.peek(); // peek character if ( c == '/' ) { std::cin >> c >> q; if (q == 0) { is.setstate(std::ios::failbit); return is; } } else { c = '/'; q = 1; } std::cout << p <
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
