Why does std::put_time not compile using multiple compilers?

丶灬走出姿态 提交于 2019-12-24 10:58:19

问题


std::put_time does not seem to work.

The following snippet is taken directly from en.cpp.reference.com.

#include <iostream>
#include <iomanip>
#include <ctime>

int main()
{
    std::time_t t = std::time(nullptr);
    std::tm tm = *std::localtime(&t);
    std::cout.imbue(std::locale("ru_RU.utf8"));
    std::cout << "ru_RU: " << std::put_time(&tm, "%c %Z") << '\n';
    std::cout.imbue(std::locale("ja_JP.utf8"));
    std::cout << "ja_JP: " << std::put_time(&tm, "%c %Z") << '\n';
}

Several compilers agree that put_time is not a member of the std library. My question is; why? Does put_time work, and if so, with which compilers and options does the example compile successfully?

clang++ 3.5.0-10 (based on LLVM 3.5.0) with -std=c++14 complains thus:

main.cc:10:36: error: no member named 'put_time' in namespace 'std'
    std::cout << "ru_RU: " << std::put_time(&tm, "%c %Z") << '\n';
                              ~~~~~^
main.cc:12:36: error: no member named 'put_time' in namespace 'std'
    std::cout << "ja_JP: " << std::put_time(&tm, "%c %Z") << '\n';
                              ~~~~~^
2 errors generated.

Gcc added support for std::put_time in version 5.0, as stated here by Jonathan Wakely.

A third "compiler" (using cpp.sh) and ticking c++14, gives:

 In function 'int main()':
10:31: error: 'put_time' is not a member of 'std'
12:31: error: 'put_time' is not a member of 'std'

I'm trying to compile this on a raspberry pi; full compiler version info:

pi@tacarmepi:~/test$ clang++ --version
Raspbian clang version 3.5.0-10+rpi1 (tags/RELEASE_350/final) (based on LLVM 3.5.0)
Target: arm-unknown-linux-gnueabihf
Thread model: posix

来源:https://stackoverflow.com/questions/44930645/why-does-stdput-time-not-compile-using-multiple-compilers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!