码迷,mamicode.com
首页 > 其他好文 > 详细

粗略了解fill与fill_n

时间:2017-10-29 23:10:56      阅读:217      评论:0      收藏:0      [点我收藏+]

标签:code   tor   nbsp   hold   font   ast   title   class   span   

以前只知道数组赋值时用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;
  }
}
 

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

(未完待续)

 

粗略了解fill与fill_n

标签:code   tor   nbsp   hold   font   ast   title   class   span   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!