zoukankan      html  css  js  c++  java
  • STL入门学习中碰到的一些函数

    2020.02.10

    • fill

      #include<algorithm>
      vector<int> v{ 1, 2, 3, 3 };
      fill(v.begin(), v.end(), 4);//正向迭代器
      cout << v.size() << endl;
      for (auto x : v)	cout << x << " ";
      
    • fill_n

      #include<algorithm>
      vector<int> v{ 1, 2, 3, 3 };
      	fill_n(v.begin(), 2, 999);//正向迭代器, 修改个数, 修改值
      	cout << v.size() << endl;
      	for (auto x : v)	cout << x << " ";
      
    • inserter

      #include<iterator>
      vector<int> v{ 1, 2, 3, 3 };
      fill_n(v.begin(), 2, 999);//覆盖 999 999 3 3
      fill_n(inserter(v, v.begin()), 2, 999);//插入 999 999 999 999 3 3
      cout << v.size() << endl;
      for (auto x : v)	cout << x << " ";
      
    • set_union

      #include<iterator>
      #define ALL(x) x.begin(), x.end()
      #define INS(x) inserter(x, x.begin())
      set_union(ALL(x1), ALL(x2), INS(x));//集合的并集运算
      set_intersection(ALL(x1), ALL(x2), INS(x));//集合的交集运算
      
    • assert

      #include<cassert>
      assert(表达式)//表达式为真时无变化,为假时强行终止程序并给错误提示
      
  • 相关阅读:
    10多媒体
    胡凡-01
    概念
    算法
    07Axios
    05VueCli
    04Vue.js路由系统
    03生命周期
    《穷人思维》学习感悟
    《基金》学习感悟之二
  • 原文地址:https://www.cnblogs.com/scl0725/p/12307576.html
Copyright © 2011-2022 走看看