fill() function in C++ STL with examples Last Updated : 11 Oct, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report The fill() function in C++ STL is used to fill some default value in a container. The fill() function can also be used to fill values in a range in the container. It accepts two iterators begin and end and fills a value in the container starting from position pointed by begin and just before the position pointed by end. Syntax: void fill(iterator begin, iterator end, type value); Parameters: begin: The function will start filling values from the position pointed by the iterator begin. end: The function will fill values upto the position just before the position pointed by the iterator end. value: This parameter denotes the value to be filled by the function in the container. NOTE : Notice carefully that ‘begin’ is included in the range but ‘end’ is NOT included. Return Value: This function does not returns any value. Below program illustrate the fill() function in C++ STL: CPP14 // C++ program to demonstrate working of fill() #include <bits/stdc++.h> using namespace std; int main() { vector<int> vect(8); // calling fill to initialize values in the // range to 4 fill(vect.begin() + 2, vect.end() - 1, 4); for (int i = 0; i < vect.size(); i++) cout << vect[i] << " "; // Filling the complete vector with value 10 fill(vect.begin(), vect.end(), 10); cout << endl; for (int i = 0; i < vect.size(); i++) cout << vect[i] << " "; return 0; } Output: 0 0 4 4 4 4 4 0 10 10 10 10 10 10 10 10 Reference: http://www.cplusplus.com/reference/algorithm/fill/ Comment More infoAdvertise with us Next Article fill() function in C++ STL with examples H harsh.agarwal0 Follow Improve Article Tags : C++ CPP-Functions Practice Tags : CPP Similar Reads fill_n() function in C++ STL with examples The fill_n() function in C++ STL is used to fill some default values in a container. The fill_n() function is used to fill values upto first n positions from a starting position. It accepts an iterator begin and the number of positions n as arguments and fills the first n position starting from the 2 min read ios operator() function in C++ with Examples The operator() method of ios class in C++ is used to any error flag of this stream is set. This includes the failbit or the badbit. Syntax: operator void*() const; Parameters: This method does not accept any parameter. Return Value: This method returns a null pointer if any error bit is set of this 1 min read iomanip setfill() function in C++ with Examples The setfill() method of iomanip library in C++ is used to set the ios library fill character based on the character specified as the parameter to this method. Syntax: setfill(char c) Parameters: This method accepts c as a parameter which is the character argument corresponding to which the fill is t 2 min read ios operator() function in C++11 with Examples The operator() method of ios class in C++11 is used to any error flag of this stream is set. This includes the failbit or the badbit. Syntax: explicit operator bool() const; Parameters: This method does not accept any parameter. Return Value: This method returns false if any error bit is set of this 1 min read fill() and fill_n() functions in C++ STL A vector, once declared, has all its values initialized to zero. Following is an example code to demonstrate the same. CPP // C++ program for displaying the default initialization // of the vector vect[] #include<bits/stdc++.h> using namespace std; int main() { // Creating a vector of size 8 v 3 min read Like