我的代码
#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;
};
错误在[17,19]中:没有运算符">gt"匹配这些操作数--操作数类型为:std::istream>gt;const双
我在网上搜索了很长时间。但没有用。请帮助或尝试给出一些如何实现这一目标的想法。非常感谢你的回答。
问问自己,你能将读入常量变量吗?读取变量会改变变量,所以答案显然是否定的。
试试这个
friend istream &operator>>(istream &input,Rectangle &D)