end_of_month_day.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /* Simple program that uses the gregorian calendar to find the last
  2. * day of the month and then display the last day of every month left
  3. * in the year.
  4. */
  5. #include "boost/date_time/gregorian/gregorian.hpp"
  6. #include <iostream>
  7. int
  8. main()
  9. {
  10. using namespace boost::gregorian;
  11. std::cout << " Enter Year(ex: 2002): ";
  12. int year, month;
  13. std::cin >> year;
  14. std::cout << " Enter Month(1..12): ";
  15. std::cin >> month;
  16. try {
  17. int day = gregorian_calendar::end_of_month_day(year,month);
  18. date end_of_month(year,month,day);
  19. //Iterate thru by months --
  20. month_iterator mitr(end_of_month,1);
  21. date start_of_next_year(year+1, Jan, 1);
  22. //loop thru the days and print each one
  23. while (mitr < start_of_next_year){
  24. std::cout << to_simple_string(*mitr) << std::endl;
  25. ++mitr;
  26. }
  27. }
  28. catch(...) {
  29. std::cout << "Invalid Date Entered" << std::endl;
  30. }
  31. return 0;
  32. }
  33. /* Copyright 2001-2004: CrystalClear Software, Inc
  34. * http://www.crystalclearsoftware.com
  35. *
  36. * Subject to the Boost Software License, Version 1.0.
  37. * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
  38. */