fill_n |
C++ Library |
template<class OutputIterator, class Size, class T> void fill_n(OutputIterator first, Size n, const T& value)
Assign n items to value, starting at position first.
#pragma warning (disable:4786) #include <algorithm> #include <iostream> int main() { int ai[10] = {10, 20, 30, 40, 50, 60, 70, 80, 90, 100} ; std::ostream_iterator<int> intOstreamIt(std::cout, ", ") ; std::cout << "ai = " ; std::copy(ai, ai+10, intOstreamIt ) ; std::cout << std::endl ; //fill first 5 elements of ai with value 25 std::fill_n(ai, 5, 25) ; std::cout << "ai, after calling fill_n = " ; std::copy(ai, ai+10, intOstreamIt ) ; std::cout << std::endl ; return 0 ; }
ai = 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, ai, after calling fill_n = 25, 25, 25, 25, 25, 60, 70, 80, 90, 100,