Advertisement
steverobinson

Steve Robinson

Aug 18th, 2010
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.79 KB | None | 0 0
  1. //<< and >> operators Overloading
  2.  
  3. #include <iostream.h>
  4.  
  5.  
  6. class Date
  7. {
  8. private:
  9.     int day, month, year;
  10. public:
  11.     Date(){}
  12.     Date(int m, int d, int y)
  13.     {
  14.         day=d;
  15.         month=m;
  16.         year=y;
  17.     }
  18.  
  19.     friend ostream& operator<<(ostream& out , Date& date);
  20.     friend istream& operator>>(istream& in, Date& date);
  21.  
  22. };
  23.  
  24. ostream& operator<<(ostream& out, Date& date)
  25. {
  26.     out << date.day << '/' << date.month << '/' << date.year <<'\n' ;
  27.     return out;
  28. }
  29.  
  30. istream& operator>>(istream& in, Date& date){
  31.     cout << "\nEnter new date [DD][MM][YY]: \n";
  32.     in>>date.day;
  33.     in>>date.month;
  34.     in>>date.year;
  35.     return in;
  36. }
  37.  
  38. int main()
  39. {
  40.     Date today(14, 8, 2010), newday;
  41.  
  42.     cout << "Today's Date: " << today << endl;
  43.  
  44.     cin >>  newday;
  45.  
  46.     cout << "\nThe new date is: " << newday << endl;
  47.  
  48.     return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement