On line 7, we create a
source containing a sequence of values that we wish to copy.
On line 9, we have another
target1, which is initialised with 5 elements. We then use
std::copy on lines 11–12 to copy values from
target1. The first two iterator arguments denote the source range, and the third iterator argument denotes the target range. We use
std::end to get these iterators for
To demonstrate how we can copy into a container that does not yet contain any elements, we create an empty
target2 on line 14. For the third argument of
std::copy (lines 16–17), we call
std::back_inserter to get an iterator that automatically calls
target2 for each element that is copied.