Formatting: how to convert 1 to “01”, 2 to “02”, 3 to "03", and so on
<p>Following code outputs the values in time format, i.e. if it's 1:50pm and 8 seconds, it would output it as 01:50:08</p>

<pre><code>cout &lt;&lt; "time remaining: %02d::%02d::%02" &lt;&lt; hr &lt;&lt; mins &lt;&lt; secs;
</code></pre>

<p>But what I want to do is (a) convert these ints to char/string (b) and then add the same time format to its corresponding char/string value.</p>

<p>I have already achieved (a), I just want to achieve (b).</p>

<p>e.g. </p>

<pre><code>    char currenthour[10] = { 0 }, currentmins[10] = { 0 }, currentsecs[10] = { 0 };

    itoa(hr, currenthour, 10);
    itoa(mins, currentmins, 10);
    itoa(secs, currentsecs, 10);
</code></pre>

<p>Now if I output 'currenthour', 'currentmins' and 'currentsecs', it will output the same example time as, 1:50:8, instead of 01:50:08.</p>

<p>Ideas?</p>