MSVC Implementation of std :: put_time

I am working with Microsoft Visual Studio 2012 and look at using std::put_time , so I created the following example:

 int main() { std::time_t t = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()); std::locale::global( std::locale("en-GB") ); std::cout << std::put_time( std::localtime( &t ), "%x" ) << std::endl; } 

This leads to the following conclusion:

 06/25/2013 

This is not a date format that I would expect from an en-GB locale. I also tried:

 std::cout.imbue( std::locale("en-GB") ); 

But then again, with the same exit. Is this what I should get for this locale, or am I mistaken somewhere?

+7
source share
1 answer

Designated work. std::put_time works in the stream locale, not in the global locale. cout is created and injected into the current global locale, before entering main . A subsequent change to the global language does not affect it. You need imbue() explicitly specify.

+4
source

All Articles