converting numbers to strings and padding the string if the number is within a specific range

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. What is the best way of doing this using the boost libraries? Any help appreciated as always. Regards Sean. __________ Information from ESET NOD32 Antivirus, version of virus signature database 4002 (20090411) __________ The message was checked by ESET NOD32 Antivirus. http://www.eset.com

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
participants (2)
-
Eugene Wee
-
Sean Farrow