std::vector我在尝试用 C++ 中的结果填充 a 时遇到问题std::views::split。具体来说,我可以成功地std::string从 的项构造 a std::ranges::split_view(如下面代码的第一个循环所示),但在尝试使用迭代器std::vector直接创建 a 时遇到困难。
// requires /std:c++20 or later
#include <ranges>
#include <iostream>
#include <vector>
int main()
{
std::string rg{ "1, 2, 3, 1, 2, 3, 4, 5, 6 "};
// Successful construction of std::string from std::ranges::split_view
for (const auto& subrange : rg | std::views::split('3'))
{
std::string value(subrange.begin(), subrange.end());
std::cout << value << '\n';
}
// Issue arises here when attempting to create std::vector
auto parts …Run Code Online (Sandbox Code Playgroud)