The following code example is taken from the book
C++23 - The Complete Guide
by Nicolai M. Josuttis,
Leanpub, 2026
The code is licensed under a
Creative Commons Attribution 4.0 International License.
// raw code
#include <print>
#include <strstream>
int main()
{
// fix-sized buffer initialized with 33 '?' and the null terminator:
constexpr int len = 33;
char buf[len+1]{};
for (int i = 0; i < len; ++i) buf[i] = '?';
std::println("buf: {:?}", buf);
// create an output stream to static char buffer (DEPRECATED):
std::ostrstream strBuf{buf, len};
double d = 47.11;
strBuf << "double d: " << d;
std::println("buf: {:?}", buf);
strBuf << " <end>";
std::println("buf: {:?}", buf);
strBuf << '\0';
std::println("buf: {:?}", buf);
}