// // datestruct.cpp // CSC 215 // John Rogers // // This program demonstrates the use of // struct to store dates and demonstrates // how to overload the << and >> operators for use // with that struct. // #include struct date { int month; int day; int year; }; ostream& operator<<(ostream& out, date d); istream& operator>>(istream& in, date& d); int main() { date d; cout << "Please enter a date: "; cin >> d; cout << "That date was: "; cout << d << endl; return 0; } // // This overloads the << operator so that // dates can be printed using it. // ostream& operator<<(ostream& out, date d) { out << d.month << "/" << d.day << "/" << d.year; return out; } // // This overloads the >> operator so that // date in the form 99/99/99 can be input using it. // istream& operator>>(istream& in, date& d) { char c; in >> d.month >> c >> d.day >> c >> d.year; return in; }