Formatting text with std::format
The C++ language has two ways of formatting text: the
printf family of functions and the I/O streams library. The
printf functions are inherited from C and provide a separation of the formatting text and the arguments. The streams library provides safety and extensibility and is usually recommended over
printf functions, but is, in general, slower. The C++20 standard proposes a new formatting library alternative for output formatting, which is similar in form to
printf but safe and extensible and is intended to complement the existing streams library. In this recipe, we will learn how to use the new functionalities instead of the
printf functions or the streams library.
The new formatting library is available in the header
<format>. You must include this header for the following samples to work.
How to do it...
std::format() function formats its arguments according to the provided formatting string. You can use...