标签:class 入门学习 size cto fine def vector 错误 cout
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(表达式)//表达式为真时无变化,为假时强行终止程序并给错误提示
标签:class 入门学习 size cto fine def vector 错误 cout
原文地址:https://www.cnblogs.com/scl0725/p/12307576.html