Background
I have a registration system that displays entries on std::ostream. Each record is annotated by a counter, which is incremented by one with each output, for example:
===== Batch # 5 =====
This is the fifth record
===== Batch # 19 =====
This is the nineteenth record
===== Batch # 187 =====
Who knows to spell *that*?
Counter std::size_ti.e. unsigned integer.
Problem
As now, the numbers are displayed without any additions, which looks ugly. I would like to achieve this:
===== Batch # 5 =====
This is the fifth record
===== Batch # 19 =====
...
===== Batch # 187 =====
===== Batch # 12345 =====
Creating a handle to a stream object can be achieved with std::setw. However, I still need to know how many digits the base-10 representation takes as much as possible.
Inquiry
(.. ), base-10 a std::size_t. , , , ++ 14 () constexpr s.
,
, N -B , ( B- N) 1. , 100 10, 100 1 3; 1234 10, ( 1234) 1 4. --:
digits( value , base ) = floor( logarithm( radicand=value , index=base ) ) + 1
; - , , . . , , .
std::size_t, std::numeric_limits<std::size_t>::max().
. , , , -.