I am using c++17 and wide characters.
I have created a function to create a wchar_t* using a variable number of parameters ...
#include <stdarg.h>
// the caller will free the memory
wchar_t* GetMessage( const wchar_t* format, ... )
{
va_list args;
va_start(args, format);
// get the size of the final string
const auto size = vswprintf(nullptr, 0, format, args);
// create the buffer
const auto buffSize = size + 1;
const auto buffer = new wchar_t[buffSize];
memset(buffer, 0, buffSize * sizeof(wchar_t) );
// create the string
vswprintf_s(buffer, buffSize, format, args);
va_end(args);
// all done
return buffer;
}
Can you suggest a more efficient, standard, way of achieving the above?