Using this library , here is the code that prints the first Monday of every month in 2011:
#include "date.h" #include <iostream> int main() { using namespace gregorian; std::cout << date_fmt("%A %B %e, %Y"); for (date d = first*mon/jan/2011; d <= dec/31/2011; d += month(1)) std::cout << d << '\n'; }
Output:
Monday January 3, 2011 Monday February 7, 2011 Monday March 7, 2011 Monday April 4, 2011 Monday May 2, 2011 Monday June 6, 2011 Monday July 4, 2011 Monday August 1, 2011 Monday September 5, 2011 Monday October 3, 2011 Monday November 7, 2011 Monday December 5, 2011
You can also get a second, third, etc. or last working day of the month. Arithmetic can be focused on a day, a month or a year.
source share