开发者

pre-calculating string length for va_list versions of _snprintf / _snwprintf

Is there a va_list style version of the following code to safely do a non-truncated sprintf:

// format a char buffer
int size = 1 + _snprintf(NULL, 0, "%d", 132);
std::vector<char> buffer (size);
sprintf_s(&buffer[0], buffer.size (), "%d", 132);

// format a wchar_t buffer
int wsize = 1 + _snwprintf(NULL, 0, L"%d", 132);
std::vector<wchar_t> wbuffer (wsize);
swprintf_s(&wbuffer[0], wbuffer.size (), L"%d", 132)开发者_C百科;

As far as I can tell from the documentation and experimentation, all the _vsnprintf functions do not return a calculation of the length, and only truncate or generate an error. Is there an alternative?


Visual Studio provides the _vscprintf function to check the amount of buffer needed to store the resulting string.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜