home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 13 / CDA13.ISO / cdactual / demobin / share / program / C / ANSICPP.ZIP / EX10016.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1990-07-24  |  544 b   |  32 lines

  1. // ex10016.cpp
  2. // Overloading the >> operator
  3. #include <iostream.h>
  4.  
  5. class Date {
  6.     int mo, da, yr;
  7. public:
  8.     Date() {}
  9.     friend ostream& operator<< (ostream& os, Date& dt);
  10.     friend istream& operator>> (istream& is, Date& dt);
  11. };
  12.  
  13. ostream& operator<< (ostream& os, Date& dt)
  14. {
  15.     os << dt.mo << '/' << dt.da << '/' << dt.yr;
  16.     return os;
  17. }
  18.  
  19. istream& operator>> (istream& is, Date& dt)
  20. {
  21.     is >> dt.mo >> dt.da >> dt.yr;
  22.     return is;
  23. }
  24.  
  25. main()
  26. {
  27.     Date dt;
  28.     cout << "Enter a date (mm dd yy): ";
  29.     cin >> dt;
  30.     cout << dt;
  31. }
  32.