Я хотел бы иметь возможность сделать следующее:
std::cerr << std::chrono::system_clock::now() << std::endl;
И получить следующее:
Wed May 1 11:11:12 2013
Поэтому я написал следующее:
template<typename Clock, typename Duration>
std::ostream &operator<<(std::ostream &stream,
const std::chrono::time_point<Clock, Duration> &time_point) {
const time_t time = Clock::to_time_t(time_point);
#if __GNUC__ > 4 || \
((__GNUC__ == 4) && __GNUC_MINOR__ > 8 && __GNUC_REVISION__ > 1)
// Maybe the put_time will be implemented later?
struct tm tm;
localtime_r(&time, &tm);
return stream << std::put_time(tm, "%c");
#else
char buffer[26];
ctime_r(&time, buffer);
buffer[24] = '\0'; // Removes the newline that is added
return stream << buffer;
#endif
}
Что работает, но я продолжаю получать проблемы при вызове этого из разных пространств имен. Правильно ли, что это должно быть просто в глобальном пространстве имен?
std
нетsystem_clock
. Это вstd::chrono
. - person Stephan Dollberg   schedule 22.05.2013<<
. - person Yakk - Adam Nevraumont   schedule 22.05.2013