Boost gregorian

I'm trying to write a program that uses the Boost library to input a string date in the format mm/dd/year and outputs to the string its corresponding day of the week. I wrote the program that I thought would accomplish this, but it doesn't seem to work. Below is the code I wrote:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <string>
#include <iostream>
#include "boost/date_time/gregorian/gregorian.hpp"

using namespace std;
using namespace boost::gregorian;

int main()
{
string ds("2002/1/25");
date d(from_simple_string(ds));
cout << d.day_of_week() << endl;
return 0;
}


When I compile this using codeblocks it gives me the error "In function `ZN5boost9date_time19month_str_to_ushortINS_9gregorian10greg_monthEEEtRKSs':|
C:\Users\rosa\Desktop\test3\..\..\..\..\Lib\boost_1_55_0\boost\date_time\date_parsing.hpp|67|undefined reference to `boost::gregorian::greg_month::get_month_map_ptr()'". And it takes me to the file date_parsing.hpp and highlights line 67. I don't understand why this isn't working. What am I doing wrong?
You need to link with libboost_date_time.
http://coliru.stacked-crooked.com/a/258e9ba85bbe7aa6
Thanks that worked (I added libboost_date_time-mgw47-mt-d-1_55.a to Link Libraries under Linker settings) and it runs correctly if I have the date 2002/1/25, but it doesn't run properly if I have the date in the format 1/25/2002. In the command prompt it outputs:

terminate called after throwing an instance of 'boost::exception_detail::clone_i
mpl<boost::exception_detail::error_info_injector<boost::gregorian::bad_day_of_mo
nth> >'
what(): Day of month value is out of range 1..31

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.

Process returned 3 (0x3) execution time : 8.542 s
Press any key to continue.
How do I get this to work regardless how the date was written? For example if it was written as 01/25/2002 or 1/25/2002 or 2002/1/25.
How do I get this to work regardless how the date was written? For example if it was written as 01/25/2002 or 1/25/2002 or 2002/1/25.
boost provides the conversion for fixed format only. The position of day and month must be unambiguous. If it wouldn't, what would 10/12/2005 be?
Last edited on
Topic archived. No new replies allowed.