|
Boost Users : |
Subject: [Boost-users] date formatting problem
From: Sergey Skorokhodov (ucayalyfish_at_[hidden])
Date: 2008-11-30 12:51:18
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
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net