provides portable definition of
and their corresponding
counterparts. On a platform that supports these functions in the standard
library, these definitions are equivalent to the standard functions. On other
platforms (mainly, older MSVC versions) these functions are emulated through
non-standard functions that have similar behavior.
Depending on the standard library, certain implementation differences are exposed to the user:
boost::core::snprintfin case if the output buffer is too small may not be equal to the number of characters that would have been written if the buffer was large enough. It is, however, equal or larger than the buffer size, which still allows the caller to detect the buffer overflow condition. The formatted output is still properly null-terminated in this case.
char buf; int n = boost::core::snprintf(buf, sizeof(buf), "%d", i); if (n < 0) throw std::runtime_error("Formatting error"); if (n >= sizeof(buf)) throw std::runtime_error("Formatting buffer overflow");