小编Saj*_*log的帖子

在 C++ 中使用 std::views::split 填充 std::vector 存在困难

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)

c++ split c++20 std-ranges

1
推荐指数
1
解决办法
126
查看次数

标签 统计

c++ ×1

c++20 ×1

split ×1

std-ranges ×1