MSVCs Implementation of std::put

I am working with Microsoft Visual Studio 2012, and was looking 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 produces the following output:

06/25/2013

Which isn't the date format I would expect from the en-GB locale. I also tried:

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

But again, with the same output. Is this what output I should be getting for this locale, or have I made a mistake somewhere?


Working as intended. std::put_time works off of the stream's locale, not the global locale. cout is created, and imbued with the current global locale, before main is entered. Subsequent change to global locale doesn't affect it. You need to imbue() it explicitly.

链接地址: http://www.djcxy.com/p/72290.html

上一篇: 语言人气数字(C ++,C#,Java,PHP,Flash脚本等)

下一篇: MSVCs执行std :: put