_itow_s和_ltow_s的用法

Usage of _itow_s and _ltow_s

本文关键字:用法 itow ltow      更新时间:2023-10-16

我想在VC8中使用MSVC的_itow_s和_ltow_s。但是我没有得到什么作为缓冲区的长度传递给这两个api。

MSDN给出了_itow_s

的如下解释
[in] sizeInCharacters
Size of the buffer in single-byte characters or wide characters.
为_ltow_s

sizeOfstr 
Size of the str in bytes for _ltoa_s or words for _ltow_s.
如果我将宽字符的数量(WCHAR)作为缓冲区的长度传递给这两个api,就像下面的
WCHAR buf[20];
_itow_s(11L, buf, sizeof(buf)/sizeof(WCHAR), 10);
_ltow_s(11L, buf, sizeof(buf)/sizeof(WCHAR), 10);

_itow_s_ltow_s期望此参数为WCHAR s的长度。您的buf类型为WCHAR,并且您正在传递WCHAR s的数量,因此它看起来是正确的。