[C++] string Formatting : Function(char * format, ...);
#include <stdlib.h>
#include <stdarg.h>
void test(char * format, ...)
{
va_list args;
int len;
char * buffer;
va_start(args, format);
len = _vscprintf(format, args) + 1;
buffer = (char*)malloc(len * sizeof(char));
vsprintf_s(buffer, len, format, args);
va_end(args);
//....
free(buffer);
}
void test(wchar_t * format, ...)
{
va_list args;
int len;
wchar_t * buffer;
va_start(args, format);
len = _vscwprintf(format, args) + 1;
buffer = (wchar_t*)malloc(len * sizeof(wchar_t));
vswprintf_s(buffer, len, format, args);
va_end(args);
//...
free(buffer);
}