Thursday, April 22, 2010

c++ - insertion operator (<<) overloading

#include"iostream"
using namespace std;
class x
{
int a,b;

public:
x()
{
a=5;
b=9;
}

friend ostream& operator<<(ostream &, x);
};

ostream& operator<<(ostream &t, x x1)
{
t << x1.a << endl;
t << x1.b;
return t;
}
int main()
{
x x1;
cout << x1;
system("pause");
return 0;
}

No comments:

Post a Comment