Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Dates, locales

Reply
Thread Tools

Dates, locales

 
 
Micah Cowan
Guest
Posts: n/a
 
      11-28-2006
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;
}
-----

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Datagrid sorting from different locales. =?Utf-8?B?YWxhbg==?= ASP .Net 0 04-21-2005 11:21 AM
Bogus locales on Mac Ellen Herzfeld Python 3 07-16-2004 05:07 PM
Correct use of locales? William Payne C++ 3 12-13-2003 09:24 PM
Python Locales under windows Moof Python 1 10-28-2003 07:27 PM
Problem installing facets into locales explicitly David List C++ 0 08-06-2003 03:37 PM



Advertisments