流运算符的重载的请教
谁能写个流运算符的重载啊?<< 和>> 谢谢大家了
#include<iostream>
using namespace std;
class example
{
public:
example(int x=0):_x(x){}
friend ostream & operator << (ostream & out, const example &e)
{
out << e._x;
return out;
}
friend istream & operator >> (istream & in, const example &e)
{
int x;
in >> x;
return in;
}
private:
int _x;
};
int main()
{
example e;
cout<<e;
cout<<endl;
cin>>e;
return 0;
}
>>重载应该是in>>e.x;
至于后面是初始化列表
[此贴子已经被作者于2006-5-19 21:44:24编辑过]