Compiling Example Code for Boost::Date_Time

Hi. I am new to Boost, and beginning with compiling example code for Boost::Date_Time. I've had success compiling the many examples given here: http://www.boost.org/doc/html/date_time/examples.html but the very first example given here: http://www.boost.org/doc/html/date_time/examples/general_usage_examples.html I cannot compile without errors. (Code given below) Changing week(1) to weeks(1) got me past the first hurdle, but still not home. The problem seems to have something to do with 'Sunday' not being of the correct type, but I'm not truly certain what is going on, hence this post ... As background, I'm using the MS VC++ 2005 compiler and Boost 1_33_1. This example fails compilation from both the IDE and the command line. I'd appreciate any insight into what would be needed to get this example to correctly compile and run. (And if there is a flaw in the example, I'd suggest that the docs be fixed to provide it in working form.) Thanks! - Steve __ using namespace boost::gregorian; date weekstart(2002,Feb,1); date weekend = weekstart + week(1); date d2 = d1 + days(5); date today = day_clock::local_day(); if (d2 >= today) {} //date comparison operators date_period thisWeek(d1,d2); if (thisWeek.contains(today)) {}//do something //iterate and print the week day_iterator itr(weekstart); while (itr <= weekend) { std::cout << (*itr) << std::endl; ++itr; } //input streaming std::stringstream ss("2004-Jan-1"); ss >> d3; //date generator functions date d5 = next_weekday(d4, Sunday); //calculate Sunday following d4 //US labor day is first Monday in Sept nth_day_of_the_week_in_month labor_day(nth_dow::first,Monday, Sep); //calculate a specific date for 2004 from functor date d6 = labor_day.get_date(2004);

Steve Johns wrote:
Hi.
I am new to Boost, and beginning with compiling example code for Boost::Date_Time.
I've had success compiling the many examples given here:
http://www.boost.org/doc/html/date_time/examples.html
but the very first example given here:
http://www.boost.org/doc/html/date_time/examples/general_usage_examples.html
I cannot compile without errors. (Code given below)
Ugh, I hate when this gets out of sync...
Changing week(1) to weeks(1) got me past the first hurdle, but still not home.
Yep.
The problem seems to have something to do with 'Sunday' not being of the correct type, but I'm not truly certain what is going on, hence this post ...
Yeah, there's a problem with the automatic conversion -- making it explicit to the type for the function (greg_weekday) does the trick for me on gcc-4. date d5 = next_weekday(d4, greg_weekday(Sunday));
I'd appreciate any insight into what would be needed to get this example to correctly compile and run. (And if there is a flaw in the example, I'd suggest that the docs be fixed to provide it in working form.)
For sure -- I noted a couple other things that prevent the 'cut from the docs, paste, and compile' technique from working. Added to my todos. Thx for the report. Thx, Jeff
participants (2)
-
Jeff Garland
-
Steve Johns