std::copy_n

cppreference.com

Example

main: () = {
    in: std::string = "1234567890";
    out: std::string = ();

    std::copy_n(in.begin(), 4, std::back_inserter(out));
    std::cout << out << '\n';

    v_in:= std::vector<int>(128);
    std::iota(v_in.begin(), v_in.end(), 1);
    v_out:= std::vector<int>(v_in.size());

    std::copy_n(v_in.cbegin(), 100, v_out.begin());
    std::cout << std::accumulate(v_out.begin(), v_out.end(), 0) << '\n';
}

Output

1234
5050

Back to top

cpp2reference.com licensed under CC-BY-SA and GFDL.