c++ 容器元素填充(generate)
#include <iostream> // cout
#include <algorithm> // generate
#include <vector> // vector
#include <ctime> // time
#include <cstdlib> // rand, srand
using namespace std;
// function generator:
int RandomNumber () { return (rand()%); } // class generator:
struct c_unique {
int current;
c_unique() {current=;}
int operator()() {return ++current;}
} UniqueNumber; int main () {
srand ( unsigned ( time() ) ); vector<int> myvector (); generate (myvector.begin(), myvector.end(), RandomNumber);// 通过函数生成 cout << "myvector contains:";
for (vector<int>::iterator it=myvector.begin(); it!=myvector.end(); ++it)
cout << ' ' << *it;
cout << '\n'; generate (myvector.begin(), myvector.end(), UniqueNumber);// 通过结构体生成 cout << "myvector contains:";
for (vector<int>::iterator it=myvector.begin(); it!=myvector.end(); ++it)
cout << ' ' << *it;
cout << '\n'; return ;
}
c++ 容器元素填充(generate)的更多相关文章
- c++ 容器元素填充指定数量的元素(generate_n)
#include <iostream> // cout #include <algorithm> // generate_n using namespace std; ; in ...
- c++ 容器元素填充(fill)
#include <iostream> // cout #include <algorithm> // fill #include <vector> // vect ...
- C++进阶 STL(3) 第三天 函数对象适配器、常用遍历算法、常用排序算法、常用算数生成算法、常用集合算法、 distance_逆序遍历_修改容器元素
01昨天课程回顾 02函数对象适配器 函数适配器是用来让一个函数对象表现出另外一种类型的函数对象的特征.因为,许多情况下,我们所持有的函数对象或普通函数的参数个数或是返回值类型并不是我们想要的,这时候 ...
- c++ STL 常用容器元素类型相关限制 指针 引用
c++ 的 STL 中主要有 vector , list, map, set , multimap,multiset 这些容器完全支持使用内置类型和指针(指针注意内存泄露问题). 就是说乱用智能指针 ...
- 5. Bean Validation声明式验证四大级别:字段、属性、容器元素、类
1024,代码改变世界.本文已被 https://www.yourbatman.cn 收录,里面一并有Spring技术栈.MyBatis.JVM.中间件等小而美的专栏供以免费学习.关注公众号[BAT的 ...
- [19/03/27-星期三] 容器_Iterator(迭代器)之遍历容器元素(List/Set/Map)&Collections工具类
一.概念 迭代器为我们提供了统一的遍历容器的方式 /* *迭代器遍历 * */ package cn.sxt.collection; import java.security.KeyStore.Ent ...
- Java提高十五:容器元素比较Comparable&Comparator深入分析
我们经常用容器来存放元素,通常而言我们是不关系容器中的元素是否有序,但有些场景可能要求容器中的元素是有序的,这个时候用ArrayList LinkedList Hashtable HashMap ...
- C++ 容器元素的存储和获取
1.存储对象,存储的是对象的副本,并不是原对象.2.获取对象,获取的是对象的引用,为什么要这样设计?a.存储对象只发生一次,而获取对象往往会有多次,获取对象,如果每次都返回对象的副本,这个开销很大.b ...
- c++ 插入容器元素(insert)
#include <iostream> #include <vector> using namespace std; int main () { vector<int&g ...
随机推荐
- linq to sql 左联接出错,未将对象引用设置到实例
var result = from a in model join b in orderDetailModel on a.FoodMenuID equals b.FoodMenuID into g f ...
- matlab 绘制条状图形
clear,clc;A=zeros(1080,1920,3);A(:,1:384,:)=0;A(:,385:768,:)=10;A(:,769:1152,:)=20;A(:,1153:1536,:)= ...
- Lintcode: Hash Function && Summary: Modular Multiplication, Addition, Power && Summary: 长整形long
In data structure Hash, hash function is used to convert a string(or any other type) into an integer ...
- mysql buffer
php与mysql的连接有三种方式,mysql,mysqli,pdo.不管使用哪种方式进行连接,都有使用buffer和不使用buffer的区别. 什么叫使用buffer和不使用buffer呢? 客户端 ...
- 2:5 视图控制器result的配置
result: 1:其实底层还是使用原来servlet的转发和重定向的方法: 2:redirectAction:只能定位到 action (比如下面name属性为 *User 的Action ,但 ...
- typed.js
实现效果,文字逐个输出. 实例代码: <script> $(function(){ $("#head-title").typed({ strings: ["为 ...
- form中的fieldset标签应用
不得不说,<fieldset>是个漂亮的家伙. 使用<fieldset>与<legend>可以设计出很好的表单. <style> fieldset:nt ...
- VS2010/MFC编程入门之五十三(Ribbon界面开发:为Ribbon Bar添加控件)
前面一节中鸡啄米为大家简单介绍了如何创建Ribbon样式的应用程序框架,本节教程就来初步讲讲怎样为Ribbon Bar添加Ribbon控件. VS2010为Ribbon界面开发提供了Ribbon De ...
- select,radio,checkbox兼容性
- iframe嵌套
iframe基本内涵 通常我们使用iframe直接直接在页面嵌套iframe标签指定src就可以了. <iframe src="demo_iframe_sandbox.htm" ...