1 /* Simple program that finds the last day of the given month, 2 * then displays the last day of every month left in the given year. 3 */ 4 5 #include "boost/date_time/gregorian/gregorian.hpp" 6 #include <iostream> 7 8 int main()9main() 10 { 11 using namespace boost::gregorian; 12 13 greg_year year(1400); 14 greg_month month(1); 15 16 // get a month and a year from the user 17 try { 18 greg_year::value_type y; 19 greg_month::value_type m; 20 std::cout << " Enter Year(ex: 2002): "; 21 std::cin >> y; 22 year = greg_year(y); 23 std::cout << " Enter Month(1..12): "; 24 std::cin >> m; 25 month = greg_month(m); 26 } 27 catch(const bad_year& by) { 28 std::cout << "Invalid Year Entered: " << by.what() << '\n' 29 << "Using minimum values for month and year." << std::endl; 30 } 31 catch(const bad_month& bm) { 32 std::cout << "Invalid Month Entered" << bm.what() << '\n' 33 << "Using minimum value for month. " << std::endl; 34 } 35 36 date start_of_next_year(year+1, Jan, 1); 37 date d(year, month, 1); 38 39 // add another month to d until we enter the next year. 40 while (d < start_of_next_year){ 41 std::cout << to_simple_string(d.end_of_month()) << std::endl; 42 d += months(1); 43 } 44 45 return 0; 46 } 47 48 /* Copyright 2001-2005: CrystalClear Software, Inc 49 * http://www.crystalclearsoftware.com 50 * 51 * Subject to the Boost Software License, Version 1.0. 52 * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 53 */ 54 55