
12 Apr
2009
12 Apr
'09
4:03 p.m.
Hi,
On Sun, Apr 12, 2009 at 11:45 PM, Sean Farrow
Hi all: I am in the process of writing a module for an application which requires me to convert a number to a string, and pad the string with a leading zero (0) if the number is within the range one to nine or in one case, one to 100.
I wonder if just using the standard library would be enough for your purposes, e.g., std::stringstream ss; ss << std::setfill('0') << std::setw(2) << num; // now use ss.str() for the string It does not quite fit your stated requirements though, e.g., setw(3) will not pad 100 to "0100", and setw(2) will pad 0 to "00", but maybe that is just inaccuracy of wording. Regards, Eugene Wee