no operator ">>" matches these operands -- operand types are: std::istream >> const double

StarGazerD

My Code

#include <iostream>
#include <stdlib.h>
#define Pi 3.14159
 
using namespace std;
 
class Rectangle
{
    public:
        friend ostream &operator<<(ostream &output,const Rectangle &D)
        {
            output<<"length:"<<D.length<<endl<<"height:"<<D.height<<endl;
            return output;
        }
        friend istream &operator>>(istream &input,const Rectangle &D)
        {
            input >> D.length >> D.height;
            return input;
        }
    private:
        double length;
        double height;
};

The error is in [17,19]:no operator ">>" matches these operands -- operand types are: std::istream >> const double

I am searching for a long time on net. But no use. Please help or try to give some ideas how to achieve this. Thank you very much for answering.

john

Ask yourself, can you read into a const variable? Reading to a variable changes the variable, so the answer is obviously no.

Try this

friend istream &operator>>(istream &input,Rectangle &D)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Error during implementation of operator>> :C++ no operator matches these operands operand types are: std::istream >> const double error

no operator matches these operands; operand types are: std::istream >> const char [5]

no operator ">>" matches these operands operand types are: std::istream >> double*

No Operator ">>" matches these operands operand types are: std::istream>>int

No operator "<" matches these operands operand types are: double < my_class

error: no match for 'operator>>' (operand types are 'std::istream' {aka 'std::basic_istream<char>'} and 'const int')|

Error C++: no operator matches these operands. operand types are: std::ostream << void

error: no match for 'operator>>' (operand types are 'std::istream' {aka 'std::basic_istream<char>'} and 'Oper')

Invalid operands of types 'double' and 'const char [13]' to binary 'operator!='

Invalid operand of types 'double' and 'const char[5]' to binary 'operator<<'

for some reason I keep getting this error: no match for 'operator>>' (operand types are 'std::istream' {aka 'std::basic_istream<char>'}

no match for 'operator<<' (operand types are 'std::ostream {aka std::basic_ostream<char>}' and 'std::_Setfill<const char*>')

No operator "+" matches these operands, aka cannot add Array<double> to double

Invalid operands of types 'int' and 'double(double*, double*, int)' to binary operator

How to understand C++ error, "no match for 'operator==' (operand types are 'std::pair' and 'const int')"?

No match for ‘operator<<’ (operand types are ‘std::ostream’ {aka ‘std::basic_ostream<char>’} and ‘const std::type_index’)

error: invalid operands of types ‘double*’ and ‘double’ to binary ‘operator/’

error: no operator "<" matches these operands

IntelliSense: no operator "<<" matches these operands

Error: no operator "==" matches these operands

no operator "/" matches these operands

no operator ""<<"" matches these operands error

Error : no operator " != " matches these operands

no operator "=" matches these operands error

"no operator >> matches these operands"

no match for 'operator<' (operand types are 'const Vehicle' and 'const Vehicle')

Accessing an entry in std::map causes 'no operator "[]" matches these operands'

invalid operands of types ‘int’ and ‘const char [15]’ to binary ‘operator<<’ ^

ERROR! invalid operands of types 'float' and 'const char [2]' to binary 'operator<<'