Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>efotinis found a good way using <strong>from_stream</strong> . </p> <hr> <p>I've looked into the manual of <code>date_time</code> and found it supports facets:</p> <pre><code>#include &lt;boost/date_time/gregorian/gregorian.hpp&gt; #include &lt;iostream&gt; #include &lt;sstream&gt; #include &lt;locale&gt; int main() { using namespace boost::gregorian; std::wstringstream ss; wdate_input_facet * fac = new wdate_input_facet(L"%Y-%m-%d"); ss.imbue(std::locale(std::locale::classic(), fac)); date d; ss &lt;&lt; L"2004-01-01 2005-01-01 2006-06-06"; while(ss &gt;&gt; d) { std::cout &lt;&lt; d &lt;&lt; std::endl; } } </code></pre> <p>You could also go with that. </p> <hr> <p>I've looked up how date facets work:</p> <ul> <li>The <code>boost::date_time::date_input_facet</code> template implements a facet. </li> <li>Facets are derived from <code>std::locale::facet</code> and every one has an unique id.</li> <li>You can <em>imbue</em> a new locale into a stream, replacing its old locale. The locale of a stream will be used for all sorts of parsing and conversions.</li> <li>When you create a new <code>std::locale</code> using the form i showed, you give it an existing locale, and a pointer to facet. The given facet will replace any existing facet of the same type in the locale given. (so, it would replace any other date_input_facet used).</li> <li>All facets are associated with the locale somehow, so that you can use <code>std::has_facet&lt;Facet&gt;(some_locale)</code> to check whether the given locale has some given facet type.</li> <li>You can use a facet from one locale by doing <code>std::use_facet&lt;Facet&gt;(some_locale).some_member...</code> .</li> <li>date_input_facet has a function get, which can be used like this:</li> </ul> <p>The below is essentially done by <code>operator&gt;&gt;</code> by boost::date_type :</p> <pre><code>// assume src is a stream having the wdate_input_facet in its locale. // wdate_input_facet is a boost::date_time::date_input_facet&lt;date,wchar_t&gt; typedef. date d; // iterate over characters of src std::istreambuf_iterator&lt;wchar_t&gt; b(src), e; // use the facet to parse the date std::use_facet&lt;wdate_input_facet&gt;(src.getloc()).get(b, e, src, d); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload