Question

Up until this point, I have been using FormatString to format multi-language strings using numbered variables ($1, $2, etc.) - however, it is not cross-platform compatible.

Is there a sprintf-esque function that is cross platform that does the same thing? It wouldn't need to allocate memory or anything - just need to be able to deal with numbered typed pseudo-variables that could be in different places in the string.

Boost is okay, if it provides a similar function.

Was it helpful?

Solution

I would have a look at boost::format. I've been using it for a while and it works very well.

Another option would be to use std::stringstreams for formatting the output. If you don't want to or cannot use boost, that's pretty much the only portable option, plus as a bonus the syntax is a little more readable IMHO.

Both libraries are type safe and thus much better and safer to use in a C++ context as well, compared to the usual C APIs.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top