粗略了解fill与fill_n

以前只知道数组赋值时用memset();

而这几天却了解到了一个函数:fill();

感觉以后会有用吧。。。

std::fill

template <class ForwardIterator, class T>
  void fill (ForwardIterator first, ForwardIterator last, const T& val);
Fill range with value

Assigns val to all the elements in the range [first,last).

The behavior of this function template is equivalent to:

1
2
3
4
5
6
7
8
template <class ForwardIterator, class T>
  void fill (ForwardIterator first, ForwardIterator last, const T& val)
{
  while (first != last) {
    *first = val;
    ++first;
  }
}
 

这个函数可以将所求区间的每一个单元的值更改为新的值;

(未完待续)

原文地址:https://www.cnblogs.com/Slager-Z/p/7751457.html