format/formatcharelems.cpp

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. Creative Commons License

// raw code

#include <print>
#include <vector>

int main()
{
  std::vector v1{'x', '\\'};
  std::println("v1: {}\n", v1);

  std::vector v2{"bold", "\\b"};
  std::println("v2: {}", v2);
  std::println("v2: {}", v2);        // format with quoting
  std::println("v2: {::}", v2);      // format without quoting
  std::println("v2: {::.2?}", v2);   // format with quoting first chars
}