home *** CD-ROM | disk | FTP | other *** search
- // ex10016.cpp
- // Overloading the >> operator
- #include <iostream.h>
-
- class Date {
- int mo, da, yr;
- public:
- Date() {}
- friend ostream& operator<< (ostream& os, Date& dt);
- friend istream& operator>> (istream& is, Date& dt);
- };
-
- ostream& operator<< (ostream& os, Date& dt)
- {
- os << dt.mo << '/' << dt.da << '/' << dt.yr;
- return os;
- }
-
- istream& operator>> (istream& is, Date& dt)
- {
- is >> dt.mo >> dt.da >> dt.yr;
- return is;
- }
-
- main()
- {
- Date dt;
- cout << "Enter a date (mm dd yy): ";
- cin >> dt;
- cout << dt;
- }