宗浩然的博客
2019-04-28 22:33C++ 为什么重载>>后调用的时候一加endl就报错
问题:C++ 为什么重载>>后调用的时候一加endl就报错
代码:
#include<iostream>
using namespace std;
class Coord{
private:
int x,y;
public:
Coord(int a=0,int b=0)
{x=a;y=b;}
friend istream &operator>>(istream &in,Coord &ob);
};
istream &operator>>(istream &input,Coord &ob)//重载>>
{
input>>ob.x;//在这一加endl就报错
input>>ob.y;
return input;
}
int main()
{
Coord a1(1,1),a2(2,2);
cin>>a1;//在这一加endl;也报错
return 0;
}
- 点赞
- 回答
- 收藏
- 复制链接分享
2条回答
为你推荐
- C++输出重载的问题。。。
- c语言
- c++
- 1个回答
- 加号运算符重载中匿名对象以及拷贝构造函数和加号运算符重载的问题?
- c++
- 1个回答
- 运算符重载之后,析构函数报错,怎么改?顺便说一下原因,谢谢
- c语言
- c++
- 2个回答
- 如何用VS2012把一个exe封装成dll并调用?
- c语言
- c++
- visual studio
- 1个回答
- 重载函数冲突
- c++
- 0个回答
换一换