It's a C++ class that basically wraps printf() so that you can call it as
This is a disaster - I looked at it and it uses vsprintf into an auto (don't
use the keyword auto) 1K buffer.
Do you work for Microsoft by any chance?
Try this one
(warning 1: untested code follows)
(warning 2: this will fail miserably if your implementation of
vsnprintf is broken - test your compiler's one first,
or download a free one from somewhere and check it)
#include <string>
#include <cstdio> // or wherever you have vsnprintf()
#include <cstdarg>
std::string str_printf(const char *fmt, ...)
{
va_list ap;
va_start (ap, fmt);
int size = vsnprintf(NULL, 0, fmt, ap);
if (size < 1) return std::string();
char *buf = new char[size+1];
va_end(ap);
va_start(ap, fmt);
vsnprintf(buf, size+1, fmt, ap);
std::string ret(buf);
delete [] buf;
return ret;
}
There is the speed disadvantage (ie. it formats everything twice to work
out the amount of memory needed), so engage your brain if you
are going to call this in a bottleneck situation.