The primary purpose of an iterator is to allow algorithms to be written in a generic manner without needing to know details about the type it's operating on. Since the algorithm only operates on the iterator type, any number of collections or other code that exposes that iterator type can be plugged into the same algorithm.
Take `std::copy_n` for example. You _could_ use this to copy from one vector to another:
std::vector<int> a = {1,2,3}, b = {0,0,0};
std::copy_n(a.begin(), a.size(), b.begin());
But iterators also allow the input and output collection types to be different:
std::vector<int> a = {1,2,3};
std::array<int,3> b;
std::copy_n(a.begin(), a.size(), b.begin());
Or even for the output to not be associated with a container at all.
std::vector<int> a = {1,2,3};
std::copy_n(a.begin(), a.size(), std::ostream_iterator<int>(std::cout, " "));
Take `std::copy_n` for example. You _could_ use this to copy from one vector to another:
But iterators also allow the input and output collection types to be different: Or even for the output to not be associated with a container at all.