使用fill_n算法

今天使用这个算法来给一个数组赋值,所以把它的使用过程记录下来:

fill_n函数的作用是:给你一个起始点,然后再给你一个数值count和val。把从起始点开始依次赋予count个元素val的值。 
注意: 不能在没有元素的空容器上调用fill_n函数 

例题:给你n个数,然后输入一些操作:start,count,paint。表示从start开始连续填充count个数字,paint为填充的数值。


// ConsoleApplication2.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"


#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main()
{
	vector<int> myvector(8, 10);        // myvector: 10 10 10 10 10 10 10 10

	fill_n(myvector.begin(), 4, 20);     // myvector: 20 20 20 20 10 10 10 10
	fill_n(myvector.begin() + 3, 3, 33);   // myvector: 20 20 20 33 33 33 10 10

	cout << "myvector contains:";
	for (auto it : myvector)
	{
		cout << " " << it;
	}

	cout << endl;

	cin.get();

	return 0;
}

激情只能点燃梦想,习惯才能成就理想

1. RPG游戏从入门到精通

2. WiX安装工具的使用
3. 俄罗斯方块游戏开发
http://edu.csdn.net/course/detail/5110
4. boost库入门基础
http://edu.csdn.net/course/detail/5029
5.Arduino入门基础
http://edu.csdn.net/course/detail/4931
6.Unity5.x游戏基础入门
http://edu.csdn.net/course/detail/4810
7. TensorFlow API攻略
http://edu.csdn.net/course/detail/4495
8. TensorFlow入门基本教程
http://edu.csdn.net/course/detail/4369
9. C++标准模板库从入门到精通 
http://edu.csdn.net/course/detail/3324
10.跟老菜鸟学C++
http://edu.csdn.net/course/detail/2901
11. 跟老菜鸟学python
http://edu.csdn.net/course/detail/2592
12. 在VC2015里学会使用tinyxml库
http://edu.csdn.net/course/detail/2590
13. 在Windows下SVN的版本管理与实战 
http://edu.csdn.net/course/detail/2579
14.Visual Studio 2015开发C++程序的基本使用 
http://edu.csdn.net/course/detail/2570
15.在VC2015里使用protobuf协议
http://edu.csdn.net/course/detail/2582
16.在VC2015里学会使用MySQL数据库
http://edu.csdn.net/course/detail/2672

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

caimouse

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值