]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/date_time/xmldoc/ex_end_of_month_day.xml
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / date_time / xmldoc / ex_end_of_month_day.xml
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
5 <!-- Copyright (c) 2001-2004 CrystalClear Software, Inc.
6 Subject to the Boost Software License, Version 1.0.
7 (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
8 -->
9
10 <section id="date_time.examples.end_of_month_day">
11 <title>End of the Months</title>
12
13 <para>
14 Iterates accross the remaining months in a given year, always landing on the last day of the month.
15 </para>
16 <programlisting>
17 <![CDATA[
18 /* Simple program that uses the gregorian calendar to find the last
19 * day of the month and then display the last day of every month left
20 * in the year.
21 */
22
23 #include "boost/date_time/gregorian/gregorian.hpp"
24 #include <iostream>
25
26 int
27 main()
28 {
29 using namespace boost::gregorian;
30
31 std::cout << " Enter Year(ex: 2002): ";
32 int year, month;
33 std::cin >> year;
34 std::cout << " Enter Month(1..12): ";
35 std::cin >> month;
36 try {
37 int day = gregorian_calendar::end_of_month_day(year,month);
38 date end_of_month(year,month,day);
39
40 //Iterate thru by months --
41 month_iterator mitr(end_of_month,1);
42 date start_of_next_year(year+1, Jan, 1);
43 //loop thru the days and print each one
44 while (mitr < start_of_next_year){
45 std::cout << to_simple_string(*mitr) << std::endl;
46 ++mitr;
47 }
48
49 }
50 catch(...) {
51 std::cout << "Invalid Date Entered" << std::endl;
52 }
53 return 0;
54
55 }
56
57 ]]>
58 </programlisting>
59 </section>