#include <iostream>
using namespace std;
class MyClass {
int x, y, z;
public:
MyClass(int a, int b, int c) { x = a; y = b; z = c; }
friend ostream &operator << (ostream &stream, MyClass obj);
friend istream &operator >> (istream &stream, MyClass &obj);
} ;
ostream &operator << (ostream &stream, MyClass obj)
{ cout<<"\n Insertion ( << ) operator\n";
stream << obj.x << ", ";
stream << obj.y << ", ";
stream << obj.z << "\n";
return stream; // return the stream
}
istream &operator >> (istream &stream, MyClass &obj)
{
cout << "\n\n Extraction ( >> ) operator\n Enter X,Y,Z values: ";
stream >> obj.x >> obj.y >> obj.z;
return stream;
}
void main()
{
MyClass a(1, 2, 3);
cout << a;
cin >> a;
cout << a;
system("pause");
}
Comments
Post a Comment