Talk:cpp/io/c/vfprintf
From cppreference.com
If I understand correctly, the invocation
int bytes = std::vsnprintf(NULL, 0, fmt, args);
will _not_ include the null terminator in the count of the number of bytes to be written, even though the other forms will include a null terminator. Is that correct? Would it be worth making that point explicit on this page?
- Good point. This page says it under "Return value" and also uses it in the example, where it does std::vector<char> buf(1+std::vsnprintf(NULL, 0, fmt, args1));. And the page on std::snprintf also says it under "Return value" and makes a slightly larger note with std::vector<char> buf(sz + 1); // note +1 for null terminator, but the C standard actually says right in the desc "not counting the terminating null character," - now done the same here. --Cubbi (talk) 12:18, 4 April 2018 (PDT)