Dates, locales

Discussion in 'C++' started by Micah Cowan, Nov 28, 2006.

  1. Micah Cowan

    Micah Cowan Guest

    I was surprised to discover that the following code emits the formatted
    date string uisng the default locale (C/POSIX), and I am required to
    uncomment the line that imbues the "ja_JP" locale into cout in order to
    get Japanese-language output.

    I am surprised by this, because I thought that the text ought to vary
    on the locale from which I obtained the time_put facet, rather than on
    the locale used by the output stream. Is G++ (v4.03) right, or is it
    something implementation-defined? Does this follow the spirit of the
    Standards intentions? Is there something to quote from the Standard to
    enlighten me, or other resources to help?

    Also, is this method even the preferred way to print a date to an
    output stream?

    -----
    #include <locale>
    #include <iostream>
    #include <ctime>
    #include <utility>

    #define CHAR_ARRAY_STR_END(a) ((a) + (sizeof(a)) - 1)

    using namespace std;

    int main(void)
    {
    const char format[] = "%c\n";
    const char *format_end = CHAR_ARRAY_STR_END(format);
    time_t secs = time(0);
    std::tm *t = localtime(&secs);

    const locale loc("ja_JP.utf8");
    // cout.imbue(loc);
    const time_put<char>& tp = use_facet<time_put<char> >(loc);
    tp.put(cout, cout, ' ', t, format, format_end);
    cout << flush;
    }
    -----
     
    Micah Cowan, Nov 28, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David Lozzi

    Dates dates dates dates... SQL and ASP.NET

    David Lozzi, Sep 29, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    881
    Rob Schieber
    Sep 30, 2005
  2. Replies:
    0
    Views:
    308
  3. PW

    Dates! Dates! Dates!

    PW, Aug 7, 2004, in forum: ASP General
    Replies:
    4
    Views:
    209
    Mark Schupp
    Aug 9, 2004
  4. Replies:
    1
    Views:
    212
    Jano Svitok
    Jul 17, 2007
  5. kellygreer1

    RFC-822 dates into Ruby dates

    kellygreer1, Jun 8, 2008, in forum: Ruby
    Replies:
    1
    Views:
    213
    Eric I.
    Jun 8, 2008
Loading...

Share This Page