zoukankan      html  css  js  c++  java
  • 算法之旅,直奔<algorithm>之十三 fill

    fill(vs2010)

    • 引言
    这是我学习总结<algorithm>的第十三篇,fill是一个很好的初始化工具。大学挺好,好好珍惜。。。
    • 作用
    fill  的作用是 给容器里一个指定的范围初始为指定的数据。
    In English, that is
    Fill range with value
    Assigns  val to all the elements in the range  [first,last).
    • 原型
    template <class ForwardIterator, class T>
      void fill (ForwardIterator first, ForwardIterator last, const T& val)
    {
      while (first != last) {
        *first = val;
        ++first;
      }
    }


    • 实验
    数据初始化为

    std::fill (myvector.begin(),myvector.begin()+4,5);

    std::fill (myvector.begin()+3,myvector.end()-2,8); 

    • 代码
    test.cpp
    #include <iostream>     // std::cout
    #include <algorithm>    // std::fill
    #include <vector>       // std::vector
    
    int main () {
    	std::vector<int> myvector (8);                       // myvector: 0 0 0 0 0 0 0 0
    
    	std::fill (myvector.begin(),myvector.begin()+4,5);   // myvector: 5 5 5 5 0 0 0 0
    	std::fill (myvector.begin()+3,myvector.end()-2,8);   // myvector: 5 5 5 8 8 8 0 0
    
    	std::cout << "myvector contains:";
    	for (std::vector<int>::iterator it=myvector.begin(); it!=myvector.end(); ++it)
    		std::cout << ' ' << *it;
    	std::cout << '
    ';
    	system("pause");
    	return 0;
    }


  • 相关阅读:
    顺序栈的基本操作(C语言)
    简单加密-维吉尼亚
    单链表的反转
    单链表的排序
    SVN信息泄露漏洞
    SQLi-labs Page-2_Less-21---Less-28a
    dedecms 任意密码重置 验证凭证回传
    ThinkCMF缓存Getshell
    ThinkCMF X2.2.0多处SQL注入漏洞
    SQLi-LABS Page-4(Challenges)
  • 原文地址:https://www.cnblogs.com/fuhaots2009/p/3478615.html
Copyright © 2011-2022 走看看