example3_copying_a_subset_of_elements.cpp

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
#include <iostream>
#include <vector>
#include <algorithm>

int main() {
    std::vector<char> source = {'a', 'b', 'c', 'd', 'e', 'f'};
    std::vector<char> destination(3);

    std::copy(source.begin() + 2, source.begin() + 5, destination.begin());

    std::cout << "Destination vector: ";
    for (const auto& ch : destination) {
        std::cout << ch << " ";
    }
    std::cout << std::endl;

    return 0;
}
Back to std_copy