date formatting problem

Hi, I'm trying to read dates in "%d%m%Y" (DDMMYYYY). Unfortunately, it doesn't work. Here is the code: #include <string> #include <stdexcept> #include <iostream> #include "boost/date_time/gregorian/gregorian.hpp" using std::string; using namespace boost::gregorian; using boost::date_time::not_a_date_time; using std::cout; using std::cin; using std::endl; using std::locale; int main() { try { date dt( not_a_date_time ); date_facet* facet(new date_facet("%d%m%Y")); cout.imbue( locale( cout.getloc(), facet ) ); cin.imbue( locale( cin.getloc(), facet ) ); cout.exceptions( std::ios_base::failbit ); cin.exceptions( std::ios_base::failbit ); cin >> dt; cout << dt << endl; } catch ( const std::exception& e ) { cout << typeid(e).name() << " " << e.what(); } return 0; } Here program output:
18111957 struct boost::gregorian::bad_month Month number is out of range 1..12
If date is assigned programmaticaly, then cout does work as expected and the date output is in %d%m%Y format. I've tried boost 1.33.1 and 1.36 What's wrong with my code? TIA

Sergey Skorokhodov wrote:
Hi,
Hi Sergey - There are 2 facets -- one for input and one for output, so your problem is easily solved. See http://www.boost.org/doc/libs/1_37_0/doc/html/date_time/date_time_io.html#da...
I'm trying to read dates in "%d%m%Y" (DDMMYYYY). Unfortunately, it doesn't work. Here is the code:
...snip...
int main() { try { date dt( not_a_date_time );
date_facet* facet(new date_facet("%d%m%Y")); ^^^^^^^^^^ ^^^^^^^^^^ date_input_facet date_input_facet
Jeff

Hi, Thanks a lot! It's really easy. Guess it's Friday evening kind of problem as I searched for date_input_facet and failed. :( Maybe, it should be emphasized in docs that date_time_input_facet should be used for both date's and dates_time's? Just to add example with date input? Anyway, thanks a lot!
There are 2 facets -- one for input and one for output, so your problem is easily solved. See
http://www.boost.org/doc/libs/1_37_0/doc/html/date_time/date_time_io.html#da...
I'm trying to read dates in "%d%m%Y" (DDMMYYYY). Unfortunately, it doesn't work. Here is the code:
...snip...
int main() { try { date dt( not_a_date_time );
date_facet* facet(new date_facet("%d%m%Y")); ^^^^^^^^^^ ^^^^^^^^^^ date_input_facet date_input_facet
participants (2)
-
Jeff Garland
-
Sergey Skorokhodov