문제

vswprintf_s : msdn link

int vswprintf_s(
   wchar_t *buffer,
   size_t numberOfElements,
   const wchar_t *format,
   va_list argptr 
);

I'm confused about the second element since MSDN states it to be:

numberOfElements Size of buffer.

However name of the argument suggests otherwise: actual number of elements to be copied into output buffer

So, if I were to have:

void print(wchar_t* format, ...){
wchar_t outString[1024];

va_list arguments;

va_start(arguments, format);
vswprintf_s(outString, sizeof(outString), format, arguments);
va_end(arguments);
}

Should I have that (size of buffer) OR:

vswprintf_s(outString, sizeof(outString)/sizeof(outString[0]), format, arguments);

Let me know.

도움이 되었습니까?

해결책

It's the number of elements.

If you look at a more recent version of the MSDN documentation (remove the (v=vs.80) portion of the URL you cited), it says:

numberOfElements: Size of buffer in characters.

(And "characters" means logical characters (code units, actually), not chars.)

Generally the "wide" versions of Windows functions use character counts, not byte sizes.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top