To print a space after every item except the final one, with any (input) iterator:
1 2 3 4 5 6 7 8 9 10 11
template <class Iter>
void print(Iter first, Iter limit)
{
while (first != limit ) {
std::cout << *first ;
++first; // first, move the iterator forward
if( first != limit ) std::cout << ' ' ; // print a space if there is a next element
}
}