.\" ident @(#)fill.3 .\" Standard Template Library .\" $$RW_INSERT_HEADER "slyrs.man" .TH fill 3C++ "02 Apr 1998" "Rogue Wave Software" "-" .ce2 Standard C++ Library Copyright 1998, Rogue Wave Software, Inc. .SH NAME \f2fill\fP, \f2fill_n\fP \ - Initializes a range with a given value. .SH SYNOPSIS .RE .RS 0 #include .br template .RE .RS 1 void fill(ForwardIterator first, ForwardIterator last, .RE .RS 11 const T& value); .RE .RS 0 .br template .RE .RS 1 void fill_n(OutputIterator first, Size n, const T& value); .SH DESCRIPTION The fill and fill_n algorithms are used to assign a value to the elements in a sequence. fill assigns the value to all the elements designated by iterators in the range \f2[first, last)\fP. The fill_n algorithm assigns the value to all the elements designated by iterators in the range \f2[first, first + n)\fP. fill_n assumes that there are at least \f2n\fP elements following \f2first\fP, unless \f2first\fP is an insert iterator. Type \f2T\fP must be Assignable, and \f2Size\fP must be convertible to an integral type. .SH COMPLEXITY fill makes exactly \f2last - first\fP assignments, and fill_n makes exactly \f2n\fP assignments. .SH EXAMPLE .RE .RS 0 // .br // fill.cpp .br // .RE .RS 1 #include .br #include .br #include .RE .RS 0 using namespace std; .br .br int main() .RE .RS 1 { .RE .RS 2 int d1[4] = {1,2,3,4}; .RE .RS 3 // .br // Set up two vectors .br // .RE .RS 2 vector v1(d1,d1 + 4), v2(d1,d1 + 4); .RE .RS 3 // .br // Set up one empty vector .br // .RE .RS 2 vector v3; .RE .RS 3 // .br // Fill all of v1 with 9 .br // .br fill(v1.begin(),v1.end(),9); .RE .RS 0 .br .RE .RS 3 // .br // Fill first 3 of v2 with 7 .br // .br fill_n(v2.begin(),3,7); .RE .RS 0 .RE .RS 3 // .br // Use insert iterator to fill v3 with 5 11's .br // .br fill_n(back_inserter(v3),5,11); .br // .br // Copy all three to cout .br // .RE .RS 2 ostream_iterator out(cout," "); .br copy(v1.begin(),v1.end(),out); .br cout << endl; .br copy(v2.begin(),v2.end(),out); .br cout << endl; .br copy(v3.begin(),v3.end(),out); .br cout << endl; .RE .RS 3 // .br // Fill cout with 3 5's .br // .br fill_n(ostream_iterator(cout," "),3,5); .RE .RS 2 cout << endl; .RE .RS 0 .RE .RS 2 return 0; .RE .RS 1 } .br .RE .RS 0 Program Output .RE .RS 0 .br 9 9 9 9 .br 7 7 7 4 .br 11 11 11 11 11 .br 5 5 5 .SH WARNINGS If your compiler does not support default template parameters, then you always need to supply the \f2Allocator\fP template argument. For instance, you have to write: \f2vector >\fP instead of: \f2vector\fP If your compiler does not support namespaces, then you do not need the using declaration for \f2std\fP.