Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //<< and >> operators Overloading
- #include <iostream.h>
- class Date
- {
- private:
- int day, month, year;
- public:
- Date(){}
- Date(int m, int d, int y)
- {
- day=d;
- month=m;
- year=y;
- }
- friend ostream& operator<<(ostream& out , Date& date);
- friend istream& operator>>(istream& in, Date& date);
- };
- ostream& operator<<(ostream& out, Date& date)
- {
- out << date.day << '/' << date.month << '/' << date.year <<'\n' ;
- return out;
- }
- istream& operator>>(istream& in, Date& date){
- cout << "\nEnter new date [DD][MM][YY]: \n";
- in>>date.day;
- in>>date.month;
- in>>date.year;
- return in;
- }
- int main()
- {
- Date today(14, 8, 2010), newday;
- cout << "Today's Date: " << today << endl;
- cin >> newday;
- cout << "\nThe new date is: " << newday << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement