---
name: "freebsd::stringf"
section: "3"
platform: "freebsd"
package: "base"
version: "16.0-CURRENT-20261027-61c70dc16a79"
release: "FreeBSD 16.0-CURRENT (2026-10-27)"
platforms: ["freebsd"]
url: "https://new.carta.tech/freebsd::stringf"
---

# freebsd::stringf(3)

build a std::string using stdio formatting

## NAME

**freebsd::stringf** – build a std::string using stdio formatting

## LIBRARY

library “libutil++”

## SYNOPSIS

**#include \<libutil++.hh\>**

*std::string*\

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

*std::string*\

**freebsd::stringf**(*const char \*fmt*, *va\_list ap*);

## DESCRIPTION

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)](/printf/3.md). The first form provides functionality similar to [asprintf(3)](/asprintf/3.md) and the second form is similar to [vasprintf(3)](/vasprintf/3.md).

## 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");
```

## SEE ALSO

[asprintf(3)](/asprintf/3.md)
