fork download
  1. #include<iostream>
  2. #include<string>
  3. using namespace std;
  4. // overloading >>, << operator
  5. class age{
  6. int x;
  7. int y;
  8. public:
  9. friend void operator<<(ostream&, age&);
  10. friend void operator>>(istream&, age&);
  11. };
  12. void operator<<(ostream& cout_ov, age &a){
  13. cout_ov<<"x = "<<a.x<<"\t"<<" and y = "<<a.y<<endl;
  14. }
  15. void operator>>(istream& cin_ov, age &a){
  16. cin_ov>>a.x>>a.y;
  17. }
  18. int main(){
  19. age a;
  20. cout<<"Enter your age and your friend's age : "<<endl;
  21. cin>>a;
  22. cout<<"Ages entered are "<<endl;
  23. cout<<a;
  24. return 0;
  25. }
  26.  
Success #stdin #stdout 0s 4480KB
stdin
18 20
stdout
Enter your age and your friend's  age :  
Ages entered are 
x = 18	 and y = 20