Limit amount of extracted subranges made by std::views::split
#include
#include
#include
#include
int main()
{
using std::operator""sv;
constexpr auto words{"Hello C++ 23!"sv};
for (const auto word : std::views::split(words, ' '))
std::cout << std::quoted(std::string_view(word)) << ' ';
std::cout << '\n';
}
This code outputs "Hello" "C++" "23!".
How to limit the split amount with n and get the output: "Hello" "C++ 23!" (with n = 1, single split from the beginning, the first subrange is Hello, the second one is all chars after the first space.)