zhiyinjixu

  博客园  :: 首页  ::  :: 联系 ::  :: 管理

 

#include <iostream.h>
class A
{
public:
A(){}
A(int a,int b):m(a),n(b) {}
public:
int m;
int n;
friend ostream& operator<< (ostream&, A&);
friend istream& operator>> (istream&, A&);
};

ostream& operator<< (ostream& out, A& e)
{
out<<e.m<<":"<<e.n;
return out;
}
istream& operator>> (istream& in,A& e)
{
in>>e.m>>e.n;
return in;
}

int main ()
{
A ob1(3,4);
cout<<ob1<<endl;
A ob2;
cin>>ob2;
cout<<ob2<<endl;
}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

posted on 2011-11-14 16:03  zhiyinjixu  阅读(165)  评论(0)    收藏  举报