Boost logo

Boost Users :

Subject: [Boost-users] ptime input_facet error with %f flag at converting string to ptime (1.36, 1.44)
From: Sören Freudiger (s.freudiger_at_[hidden])
Date: 2011-06-30 08:30:06

I have problems with reading the time fraction at converting from string
to ptime. Here is the regarding soruce code:

|#include <iostream>
#include <string>
#include <boost/date_time.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/date_time/gregorian/gregorian.hpp>
#include <boost/date_time/posix_time/conversion.hpp>

int main( int, char * )
    using namespace std;
    using namespace boost;
    using namespace boost::posix_time;
    using namespace boost::local_time;
    using namespace boost::gregorian;

    time_facet* output_facet= new time_facet();
    time_input_facet* input_facet= new time_input_facet();

    stringstream sstream;
    sstream.imbue(locale(locale::classic(), output_facet));
    sstream.imbue(locale(sstream.getloc() , input_facet));

    string format("%d/%m/%Y %H:%M:%S.%f"); //example works fine without %f!!!
    output_facet->format( format.c_str()
    input_facet->format( format.c_str() <

    ptime dt= microsec_clock().local_time();

    sstream<< dt;
    cout<< sstream.str() << end
    string time_string= sstream.str();

    ptime tgtDt( boost::date_time::not_a_date_time);
    sstream.str( time_string.c_str()
    sstream>> tgtDt;
    cout<< tgtDt<< endl;

The program runs fine without the %f inside the format string. But with
%f tgtDt is "not-a-date-time". I use boost 1.44 and the doc says %f
shold work, because every input incompatible format flag is marked bei
"!" in the documentation.

Any ideas how to get the frac part out of a string?

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at