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">
5 <!-- Copyright (c) 2001-2005 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)
10 <section id=
"date_time.examples.end_of_month_day">
11 <title>Last Day of the Months
</title>
14 Example that gets a month and a year from the user and finds the last day of each remaining month of that year.
18 /* Simple program that finds the last day of the given month,
19 * then displays the last day of every month left in the given year.
22 #include
"boost/date_time/gregorian/gregorian.hpp"
28 using namespace boost::gregorian;
33 // get a month and a year from the user
36 std::cout <<
" Enter Year(ex: 2002): ";
39 std::cout <<
" Enter Month(1..12): ";
41 month = greg_month(m);
44 std::cout <<
"Invalid Year Entered: " << by.what() << '\n'
45 <<
"Using minimum values for month and year." << std::endl;
48 std::cout <<
"Invalid Month Entered" << bm.what() << '\n'
49 <<
"Using minimum value for month. " << std::endl;
52 date start_of_next_year(year+
1, Jan,
1);
53 date d(year, month,
1);
55 // add another month to d until we enter the next year.
56 while (d < start_of_next_year){
57 std::cout << to_simple_string(d.end_of_month()) << std::endl;