String formatting
String formatting has traditionally been a weak point with the STL. Until recently, we've been left with an imperfect choice between the cumbersome STL iostreams
or the archaic legacy printf()
. Beginning with C++20 and the format
library, STL string formatting has finally grown up. Closely based on Python's str.format()
method, the new format
library is fast and flexible, providing many of the advantages of both iostreams
and printf()
, along with good memory management and type safety.
For more about the format
library, see the Format text with the new format library recipe in Chaper 1, New C++20 Features.
While we no longer need to use iostreams
for string formatting, it is still quite useful for other purposes, including file and stream I/O, and some type conversions.
In this chapter, we will cover these subjects and more in the following recipes:
- Use
string_view
as a lightweight string object - Concatenate strings
- Transform strings...