Files
date_time/doc/exp-print_month.html
Jeff Garland a56477b83f fix example bug, update to use iostream
[SVN r16074]
2002-11-02 22:26:35 +00:00

71 lines
3.0 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Example Documentation</title><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head>
<body bgcolor="#ffffff"> <!-- Generated by Doxygen 1.2.17 -->
<hr>
<h1>print_month.cpp</h1>
Simple utility to print out days of the month with the days of a month.
Demontstrates date iteration (date_time::date_itr).
<p></p>
<div class="fragment" id="DIV1"><pre><font class="comment">/*</font>
<font class="comment">This example prints all the dates in a month. It demonstrates</font>
<font class="comment">the use of iterators as well as functions of the gregorian_calendar</font>
<font class="comment"></font>
<font class="comment">Output:</font>
<font class="comment">Enter Year: 2002</font>
<font class="comment">Enter Month(1..12): 2</font>
<font class="comment">2002-Feb-01 [Fri]</font>
<font class="comment">2002-Feb-02 [Sat]</font>
<font class="comment">2002-Feb-03 [Sun]</font>
<font class="comment">2002-Feb-04 [Mon]</font>
<font class="comment">2002-Feb-05 [Tue]</font>
<font class="comment">2002-Feb-06 [Wed]</font>
<font class="comment">2002-Feb-07 [Thu]</font>
<font class="comment">*/</font>
<font class="preprocessor">#include "boost/date_time/gregorian/gregorian.hpp"</font>
<font class="preprocessor">#include &lt;iostream&gt;</font>
<font class="keywordtype">int</font>
main()
{
std::cout &lt;&lt; <font class="stringliteral">"Enter Year: "</font>;
<font class="keywordtype">int</font> year, month;
std::cin &gt;&gt; year;
std::cout &lt;&lt; <font class="stringliteral">"Enter Month(1..12): "</font>;
std::cin &gt;&gt; month;
<font class="keyword">using</font> <font class="keyword">namespace </font>boost::gregorian;
try {
<font class="comment">//Use the calendar to get the last day of the month</font>
<font class="keywordtype">int</font> eom_day = gregorian_calendar::end_of_month_day(year,month);
date endOfMonth(year,month,eom_day);
<font class="comment">//construct an iterator starting with first day of the month</font>
day_iterator ditr(date(year,month,1));
<font class="comment">//loop thru the days and print each one</font>
<font class="keywordflow">for</font> (; ditr &lt;= endOfMonth; ++ditr) {
std::cout &lt;&lt; *ditr &lt;&lt; <font class="stringliteral">" ["</font>
&lt;&lt; ditr-&gt;day_of_week() &lt;&lt; <font class="stringliteral">"]"</font>
&lt;&lt; std::endl;
}
}
<font class="keywordflow">catch</font>(std::exception&amp; e) {
std::cout &lt;&lt; <font class="stringliteral">"Error bad date, check your entry: \n"</font>
&lt;&lt; <font class="stringliteral">" Details: "</font> &lt;&lt; e.what() &lt;&lt; std::endl;
}
<font class="keywordflow">return</font> 0;
}
</pre>
</div>
<hr>
<address><small> Generated Wed Aug 21 16:54:33 2002 by Doxygen for CrystalClear
Software © 2000-2002</small></address>
</body>
</html>