ex_end_of_month_day.xml 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <!DOCTYPE library PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN"
  3. "../../../tools/boostbook/dtd/boostbook.dtd">
  4. <!-- Copyright (c) 2001-2004 CrystalClear Software, Inc.
  5. Subject to the Boost Software License, Version 1.0.
  6. (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
  7. -->
  8. <section id="date_time.examples.end_of_month_day">
  9. <title>End of the Months</title>
  10. <para>
  11. Iterates accross the remaining months in a given year, always landing on the last day of the month.
  12. </para>
  13. <programlisting>
  14. <![CDATA[
  15. /* Simple program that uses the gregorian calendar to find the last
  16. * day of the month and then display the last day of every month left
  17. * in the year.
  18. */
  19. #include "boost/date_time/gregorian/gregorian.hpp"
  20. #include <iostream>
  21. int
  22. main()
  23. {
  24. using namespace boost::gregorian;
  25. std::cout << " Enter Year(ex: 2002): ";
  26. int year, month;
  27. std::cin >> year;
  28. std::cout << " Enter Month(1..12): ";
  29. std::cin >> month;
  30. try {
  31. int day = gregorian_calendar::end_of_month_day(year,month);
  32. date end_of_month(year,month,day);
  33. //Iterate thru by months --
  34. month_iterator mitr(end_of_month,1);
  35. date start_of_next_year(year+1, Jan, 1);
  36. //loop thru the days and print each one
  37. while (mitr < start_of_next_year){
  38. std::cout << to_simple_string(*mitr) << std::endl;
  39. ++mitr;
  40. }
  41. }
  42. catch(...) {
  43. std::cout << "Invalid Date Entered" << std::endl;
  44. }
  45. return 0;
  46. }
  47. ]]>
  48. </programlisting>
  49. </section>