thanks Gavin for valuable inputs. Good day.


On Mon, Nov 4, 2013 at 6:13 AM, Gavin Lambert <gavinl@compacsort.com> wrote:
On 3/11/2013 01:12, Quoth Rahul Mathur:

YES, the string should contain a valid integer. Thanks all ..!!

Actually the string must consist entirely of a valid integer, not merely contain one.  Any non-numeric characters are invalid.


1. One string as "Apple"
2. Another string or int value as "01" or 1.
3. Final third being a string or int value as "000" or 1.

CASE:A I have to print as -> Apple01001  with the last three digits from
right being incremented when needed e.g Apple01001, Apple01002,
Apple01003 and so on..

CASE:B Also, the fourth and fifth digit from right being incremented
when needed, alongwith last three digits from right as - Apple02001,
Apple02002, Apple02003 and so on ..

If you already have the components broken out like that, then it is trivial to convert "001" to 1 via lexical_cast, and then do whatever operations you want on each component separately.  (If you don't have them broken out, then you will need to use some kind of parser to break them out into components first.)

You can't use lexical_cast to go the other way and produce "001" from 1 -- it will produce only "1", and you would have to use something else to insert the leading zeroes that you desire.

You might want to look at Boost.Format, eg:

  (boost::format("%1%%|2$02|%|3$03|") % tid % tagId % value).str()



_______________________________________________
Boost-users mailing list
Boost-users@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users