Бих искал да мога да направя следното:
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
}
Което работи, но продължавам да получавам проблеми, когато извиквам това от различни пространства на имена. Правилно ли е това да е само в глобалното пространство на имената?
system_clock
вstd
. Това е вstd::chrono
. - person Stephan Dollberg   schedule 22.05.2013<<
претоварване. - person Yakk - Adam Nevraumont   schedule 22.05.2013