C++ std::fill_n with std::array














































C++ std::fill_n with std::array



/* Function:- Assign given value to elements of given range. Possible forms:- template <class OutputIterator, class Size, class T> OutputIterator fill_n (OutputIterator first, Size n, const T& val); Return value:- None */ #include <iostream> #include <algorithm> #include <array> using namespace std; int main(){ array<int, 5> container; cout << "Before : "; for (auto& elt: container) cout << elt << ' '; fill_n(container.begin(),3, 20); fill_n(container.begin()+3,2, 10); cout << "\nAfter : "; for (auto& elt: container) cout << elt << ' '; return 0; } /* OUTPUT :- Before : -1204444096 21859 -1204445024 21859 -14473968 After : 20 20 20 10 10 */

Comments