|
Boost Users : |
Subject: Re: [Boost-users] date_time question
From: Amadeus W.M. (amadeus84_at_[hidden])
Date: 2008-12-21 18:59:19
On Sun, 21 Dec 2008 17:35:55 +0100, Václav Haisman wrote:
> Amadeus W.M. wrote, On 21.12.2008 16:31:
>> I want to read from stdin files that contain dates and data. The files
>> come from various sources so the dates are in different formats. Of
>> course, the problem is reading the dates. Based on the date_time
>> examples I put together a few lines of code using facets that I thought
>> should work, but it doesn't seem to. Can't tell if I'm way off, or I'm
>> missing something small.
>>
>>
>> #include <boost/date_time/posix_time/posix_time.hpp>
>>
>> using namespace boost::posix_time;
>> using namespace std;
>>
>> int main(int argc, char * argv[])
>> {
>> // Create a facet with the expected format. time_input_facet *
>> tfacet=new time_input_facet("%Y/%m/%d %H:%M:%S");
>>
>> ptime pt(not_a_date_time);
>> cin.imbue(locale(cin.getloc(),tfacet)); cin >> pt;
>> cout << pt << endl; // pt still not_a_date_time.
>>
>> return 0;
>> }
>>
>>
>> Compilation:
>>
>>
>> g++ -g -Wall -o facets -I/usr/local/include/boost-1_35
>> -L/usr/local/lib/ facets.C -lboost_date_time-gcc43-mt-1_35
>>
>> Run:
>>
>> echo "12/20/2008 09:56:00" | ./facets
> Your format string is "%Y/%m/%d %H:%M:%S". The date format and the
> string you accept are obviously not compatible.
>
>> not-a-date-time # pt unchanged
>>
>>
>> Once I sort out how to read dates from stdin (initially with the format
>> hard-coded) I have to figure out how to parse the date and guess the
>> format internally in the program.
>>
>>
>> Please help! Thanks!
Thanks! It's things like this that make me want to bang my head against a
wall sometimes.
Now how do I go about guessing the format?
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