Copy from One Iterator to Another

Learn to copy from one iterator to another.

We'll cover the following

The copy algorithms are generally used to copy from and to containers, but in fact, they work with iterators, which is far more flexible.

How to do it

In this recipe, we will experiment with std::copy and std::copy_n to get a good understanding of how they work:

  • Let's start with a function to print a container:

Get hands-on with 1200+ tech skills courses.