The following code example is taken from the book
C++20 - The Complete Guide
by Nicolai M. Josuttis,
Leanpub, 2021
The code is licensed under a
Creative Commons Attribution 4.0 International License.
// raw code
#include "always40.hpp"
#include "formatalways40.hpp"
#include <iostream>
int main()
{
try {
Always40 val;
std::cout << val.getValue() << '\n';
std::cout << std::format("Value: {}\n", val);
std::cout << std::format("Twice: {0} {0}\n", val);
std::cout << std::format("With width: '{:07}'\n", val);
}
catch (std::format_error& e) {
std::cerr << "Format Error: " << e.what() << std::endl;
}
}