/ Published in: C++
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
std::string format_arg_list(const char *fmt, va_list args) { if (!fmt) return ""; int result = -1, length = 256; char *buffer = 0; while (result == -1) { if (buffer) delete [] buffer; buffer = new char [length + 1]; memset(buffer, 0, length + 1); result = _vsnprintf(buffer, length, fmt, args); length *= 2; } std::string s(buffer); delete [] buffer; return s; } std::string format(const char *fmt, ...) { va_list args; va_start(args, fmt); std::string s = format_arg_list(fmt, args); va_end(args); return s; }