Take the 2-minute tour ×

Usually I use streams for formatting stuff however in this case ?I don't know the format until runtime.

I want to be able to take something like the following format string:
Hello {0}! Your last login was on {1,date:dd/mm/yy}.
...and feed in the variables "Fire Lancer" and 1247859223, and end up with the following formatted string:
Hello Fire Lancer! Your last login was on 17/07/09.

In other languages I use there is built in support for this kind of thing, eg pythons format string method, however in c++ there doesn't seem to be any such functionality, accept the C print methods which are not very safe.

Also this is for a high performance program, so whatever solution I use needs to parse the format string once and store it (eg mayby a Parse method that returns a FormatString object with a Format(string) method), not reparse the string every time the format method is called...

share|improve this question
Your high-performance program rapidly greets the user? –  GManNickG Jul 17 '09 at 19:42
@GMan hahahahaha. Im still asking myself that question too –  Edison Gustavo Muenz Jul 17 '09 at 20:03
add comment

3 Answers

Your format string looks very much like those used in ICU MessageFormat. Did you consider using it?

share|improve this answer
add comment

Boost Formatting does that for you:


Check out this question and answer for examples of usage:

share|improve this answer
add comment

boost::format will do the positional arguments portion, but not the date formatting...

share|improve this answer
add comment

Your Answer


