This is not the same function, no. std::fill fills the range, given the start and end iterator. std::fill_n fills a certain number of elements, given the initial iterator and quantity. fill_n is useful for output iterators when there is no way to get the final iterator, for example, using std::ostream_iterator :
std::fill( std::ostream_iterator<int>(std::cout), ???, x); ^^^ what do I put here? std::fill_n( std::ostream_iterator<int>(std::cout), 25, x);
source share