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

IntelliSense: no operator "<<" matches these operands

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

error: no operator "<" matches these operands

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

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

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

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

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

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

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

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

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

Error : no operator " != " matches these operands

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

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

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

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

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

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

Error: no operator "==" matches these operands

no operator "=" matches these operands error

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

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

"no operator >> matches these operands"

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

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

no operator "/" matches these operands

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

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