为什么std :: put_time不能使用多个编译器进行编译?

时间:2017-07-05 15:38:52

标签: c++ c++11 raspberry-pi g++ llvm-clang

std::put_time似乎不起作用。

以下代码段为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';
}

有几个编译器同意put_time不是std库的成员。我的问题是;为什么? put_time是否有效,如果是,那么编译器和选项是否成功编译?

clang ++ 3.5.0-10(基于LLVM 3.5.0),其中-std = c ++ 14抱怨:

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在版本5.0中添加了对std :: put_time的支持,如Jonathan Wakely所述。

third "compiler" (using cpp.sh)并勾选c ++ 14,给出:

 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'

我试图在覆盆子pi上编译它;完整的编译器版本信息:

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

0 个答案:

没有答案