我有一个uint128_t
将其值存储为的类,uint64_t UPPER, LOWER;
我不知道如何重载,operator<<
以便当我传入时std::cout
,该值将以十进制正确打印。目前,我只是在做
std::ostream & operator<<(std::ostream & stream, uint128_t const & rhs){
if (rhs.upper()) // if the upper value has a non-zero digit
stream << rhs.upper();
// i need some way to pad this so that the number of 0s between
// upper and lower is correct
stream << rhs.lower();
return stream;
我应该怎么办?
编辑:
例子:
如果 uint128_t 变量具有UPPER = 1
and LOWER = 1
,我希望流包含十进制值(1 << 64) + 1