fill()函数使用方法

fill()函数可以把数组或容器中的某一段区间赋为某个相同的值。与memset有近似之处。

测试代码:

#include<iostream>

#include<algorithm>

using namespace std;

int main(){

int a[3] = {1,2,3};

fill(a,a+3,3);

for(int i=0;i<3;i++)

cout<<a[i]<<endl;

vector<char> v(5);

fill(v.begin(),v.end(),'*');        

for(auto it=v.begin();it!=v.end();it++)

cout<<*it;

}

输出:

3

3

3

*****

猜你喜欢

转载自www.cnblogs.com/younanyihu/p/12366952.html
今日推荐