std::fill
cppreference.com
<tbody>
</tbody>
template< class ForwardIt, class T > void fill( ForwardIt first, ForwardIt last, const T& value ); |
||
value [first, last).
[first, last)
|
||
| value | ||
-ForwardIt ForwardIterator.
| ||
()
last - first .
template< class ForwardIt, class T >
void fill(ForwardIt first, ForwardIt last, const T& value)
{
for (; first != last; ++first) {
*first = value;
}
}
|
fill(), -1:
#include <algorithm>
#include <vector>
#include <iostream>
int main()
{
int data[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }
std::vector<int> v1(data, data+10);
std::fill(v1.begin(), v1.end(), -1);
for (vector<int>::iterator it = v1.begin(); it != v1.end(); ++it) {
std::cout << *it << " ";
}
std::cout << "\n";
}
:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1
.
| ( ) | |
| ( ) | |
| , ( ) |