//********************************************************
// 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()
{
  char input[] = "10 20 30 7.7";

  // initialize a span stream that reads from input:
  // - ensure the null terminator is not processed by the span stream
  std::ispanstream ispStrm{{input, sizeof(input)-1}};

  // as long as possible read ints and print them out:
  while (ispStrm) {
    int i;
    ispStrm >> i;
    if (ispStrm) {
      std::println("read {}", i);
    }
  }

  if (!ispStrm.eof()) {
    std::println("WARNING: not all input processed");
  }
}

