fork download
  1. #include <iomanip>
  2. #include <iostream>
  3. #include <ostream>
  4.  
  5. class Date
  6. {
  7. int day, month, year;
  8.  
  9. public:
  10.  
  11. Date() : day(1), month(1), year(1970)
  12. {
  13. }
  14.  
  15. Date(int d, int m, int y) : day(d), month(m), year(y)
  16. {
  17. }
  18.  
  19. friend std::ostream & operator << (std::ostream &, const Date &d);
  20. };
  21.  
  22. std::ostream & operator << (std::ostream &os, const Date &d)
  23. {
  24. os << std::setw(6) << "Day" << std::setw(10) << "Month" << std::setw(10) << "Year" << '\n';
  25. os << std::setw(30) << std::setfill('-') << '\n' << std::setfill(' ');
  26. os << std::setw(6) << d.day << std::setw(10) << d.month << std::setw(10) << d.year << std::flush;
  27. return os;
  28. }
  29.  
  30. int main()
  31. {
  32. Date date(7, 1, 2001);
  33.  
  34. std::cout << date << '\n';
  35. }
  36.  
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
   Day     Month      Year
-----------------------------
     7         1      2001