freebsd::stringf(3)

freebsd::stringf3

Build a std::string using stdio formatting

Usage

#include <libutil++.hh>

std::string

freebsd::stringf(const char *fmt, ...);

std::string

freebsd::stringf(const char *fmt, va_list ap);

Library

library “libutil++”

Overview

These functions construct a std::string object containing a formatted string. The output of the string is dictated by the fmt argument and additional arguments using the same conventions documented in printf(3). The first form provides functionality similar to asprintf(3) and the second form is similar to vasprintf(3).

Return values

These functions return a std::string object.

Exceptions

These functions may throw one of the following exceptions:

[std::bad_alloc]

Failed to allocate memory.

[std::length_error]

The result would exceeed the maximum possible string size.

Examples

std::string s = freebsd::stringf("hello %s", "world");

Releases

Unchanged in 3 releases since FreeBSD 15.0-RELEASE.

  1. 15.0–16.0

From base 16.0-CURRENT-20261027-61c70dc16a79 in FreeBSD 16.0-CURRENT (2026-10-27). Parsed by carta from the page's mdoc source.