【发布时间】:2021-02-15 01:00:41
【问题描述】:
我有以下玩具代码:
#include "date/date.h"
#include <iostream>
using namespace std;
using namespace chrono;
int main() {
cout << microseconds(100);
};
但是,它不起作用,因为:
C2679: binary '<<': no operator found which takes a right-hand operand of type 'std::chrono::milliseconds' (or there is no acceptable conversion)
但是docs 的date.h 列出了规范:
template <class CharT, class Traits, class Rep, class Period>
std::basic_ostream<CharT, Traits>&
operator<<(std::basic_ostream<CharT, Traits>& os,
const std::chrono::duration<Rep, Period>& d);
它将使用get_units 输出适当的单位。
那么,我该如何正确使用这个重载的<< 运算符呢?
【问题讨论】:
-
您的代码看起来与duration 中的示例不同。