ostream& operator<<(ostream& ost, const date &d) { ost << d.month << "/" << d.day << "/" << d.year; return ost; } istream& operator>>(istream& ist, date& d) { int month; //uninitialized variable ist >> month; if (!ist) { //if (ist.operator!()) { return ist; } char c; //uninitialized variable ist >> c; if (!ist) { return ist; } if (c != '/') { ist.setstate(ios_base::failbit); return ist; } int day; //uninitialized variable ist >> day; if (!ist) { return ist; } ist >> c; if (!ist) { return ist; } if (c != '/') { ist.setstate(ios_base::failbit); return ist; } int year; //uninitialized variable ist >> year; if (!ist) { return ist; } //Put no values into d until we've verified that all three are valid. if (month < date::january || month > date::december) { cerr << "bad month " << month << "\n"; ist.setstate(ios_base::failbit); return ist; } if (day < 1 || day > date::length[month]) { cerr << "bad day " << day << " of month " << month << "\n"; ist.setstate(ios_base::failbit); return ist; } d.year = year; d.month = month; d.day = day; return ist; //as in the above line 4 }