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.
g++ 4.9.2-10 with -std=c++14 complains thus:
main.cc: In function ‘int main()’:
main.cc:10:31: error: ‘put_time’ is not a member of ‘std’
std::cout << "ru_RU: " << std::put_time(&tm, "%c %Z") << '\n';
^
main.cc:12:31: error: ‘put_time’ is not a member of ‘std’
std::cout << "ja_JP: " << std::put_time(&tm, "%c %Z") << '\n';
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
pi@tacarmepi:~/test$ g++ --version
g++ (Raspbian 4.9.2-10) 4.9.2
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Aucun commentaire:
Enregistrer un commentaire