[date_time] how to parse "1/13/2006"

Hi! I have to read in a file format where the date is given as month/day/year, but without leading '0' for day and month.
From http://boost.org/doc/html/date_time/date_time_io.html I could not guess how to declare the facet format string (No leading zeroes required)
Could you please complete the following code? std::istringstream iss; local_time_input_facet* input_facet = new local_time_input_facet(); ss.imbue(locale(ss.getloc(), input_facet)); input_facet->format("???????"); regards, Markus

Markus Werle <numerical.simulation <at> web.de> writes:
Hi!
I have to read in a file format where the date is given as month/day/year, but without leading '0' for day and month.
From http://boost.org/doc/html/date_time/date_time_io.html I could not guess how to declare the facet format string (No leading zeroes required)
Could you please complete the following code?
std::istringstream iss; local_time_input_facet* input_facet = new local_time_input_facet(); ss.imbue(locale(ss.getloc(), input_facet)); input_facet->format("???????");
Though the docs do not state it, the leading zeores can be omitted during read in, so the output of #include <boost/date_time/posix_time/posix_time.hpp> #include <boost/date_time/gregorian/gregorian.hpp> #include <boost/date_time/local_time/local_time.hpp> #include <iostream> #include <sstream> int main() { try { using namespace boost::posix_time; using namespace boost::gregorian; using namespace boost::local_time; std::istringstream iss("1/13/2006"); local_time_input_facet* input_facet = new local_time_input_facet(); iss.imbue(std::locale(iss.getloc(), input_facet)); input_facet->format("%m/%d/%Y"); ptime p; iss >> p; std::cout << p << std::endl; } catch (std::exception const & e) { std::cerr << e.what() << std::endl; } catch (...) { std::cerr << "CRASH!!" << std::endl; } } is 2006-Jan-13 00:00:00
participants (1)
-
Markus Werle