Writes to a sized buffer given a format string and zero or more arguments.
Declared in <absl/strings/str_format.h>
template<typename... Args>
int
SNPrintF(
char* output,
std::size_t size,
FormatSpec<Args...> const& format,
Args const&... args);
This function is functionally equivalent to std::snprintf() (and type-safe); prefer absl::SNPrintF() over std::snprintf().
In particular, a successful call to absl::SNPrintF() writes at most size bytes of the formatted output to output, including a NUL-terminator, and returns the number of bytes that would have been written if truncation did not occur. In the event of an error, a negative value is returned and errno is set.
Example:
std::string_view s = "Ulaanbaatar"; char output[128]; absl::SNPrintF(output, sizeof(output), "The capital of Mongolia is %s", s);
Post-condition: output == "The capital of Mongolia is Ulaanbaatar"
The number of bytes that would have been written, or a negative value on error.
| Name | Description |
|---|---|
| output | The buffer to write to. |
| size | The size of the buffer, in bytes. |
| format | The format string. |
| args | The arguments substituted into the format string. |