I have a wrapper function that allows me to achieve the result of sprintf
by writing one line of code instead of 3.
void output(const tstring& format, ...)
{
va_list args;
va_start(args, format);
const int len = _vsctprintf(format.c_str(), args) + 1;
TCHAR* buf = new TCHAR[len];
_vstprintf(buf, format.c_str(), args);
OutputDebugString(buf);
delete[] buf;
}
My problem: The variadic arguments are corrupted.
For example;
output(_T("%d\n"), 1); // outputs: -858993460
output(_T("%d\n"), 2); // outputs: -858993460
Whats the cause of this error and how can I fix it?