gcc 4.4.4: std::time_put facet instantiation, and locale imbue-ing
Sun Jun 6 21:11:00 GMT 2010
I don't understand the logic I'm seeing with libstdc++'s instantiation of
the time_put facet from a locale, and then using the facet to format a date
into an ostream. It appears that time_put's locale gets ignored. The locale
that's imbued in the ostream governs formatting of date/time localized
const std::time_put<char> &t(std::use_facet<std::time_put<char> > (l));
struct tm tmbuf;
const char *fmt="%B-%d-%Y";
t.put(std::ostreambuf_iterator<char>(std::cout), std::cout, ' ', &tmbuf,
std::cout << std::endl;
I couldn't get this to work until I stuck that imbue in there. I'm trying to
If I take out the imbue call, the month name that gets formatted to cout
comes from the C/POSIX locale, even though "t" is a facet from the fr_FR
locale. I can't figure out why I instantiate a locale, get its time_put
facet, and use it to format a struct tm, when the locale gets subsequently
ignored in favor of what's imbued in the ostream.
If in the sample code, I change:
Then I get fr_FR locale written to cout, which suggests that the imbued
locale in the ostream governs the date/time localization.
So, it appears to me that it's completely irrelevant from which locale the
std::time_put facet gets instantiated from, it's the locale imbued into the
output stream that determines the output locale. What is the logic for this?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Size: 198 bytes
Desc: not available
More information about the Gcc-help