//********************************************************
// The following code example is taken from the book
//  C++23 - The Complete Guide
//  by Nicolai M. Josuttis (www.josuttis.com)
//  https://www.cppstd23.com
//
// The code is licensed under a
//  Creative Commons Attribution 4.0 International License
//  https://creativecommons.org/licenses/by/4.0/
//********************************************************


#include <print>
#include <spanstream>

int main()
{
  // fix-sized buffer initialized with 33 '?' and a null terminator:
  constexpr int len = 33;
  char buf[len+1]{};
  for (int i = 0; i < len; ++i) buf[i] = '?';
  std::println("buf: {:?}", buf);

  // create a span stream to the whole static char buffer:
  std::ospanstream strBuf{buf};

  double d = 47.11;
  std::print(strBuf, "double d: {}", d);
  std::println("buf: {:?}", buf);

  std::print(strBuf, " <end>");
  std::println("buf: {:?}", buf);

  strBuf.put('\0');                // ensure buf ends with a null terminator
  std::println("buf: {:?}", buf);
}

