【c++基础】vector初始化的几种方式
前言
STL中的vector有几种初始化方式,根据不同的需求选择合适的初始化方式。
源码
// constructing vectors
#include <iostream>
#include <vector> int main ()
{
// constructors used in the same order as described above:
std::vector<int> first; // empty vector of ints
std::vector<int> second (,); // four ints with value 100
std::vector<int> third (second.begin(),second.end()); // iterating through second
std::vector<int> fourth (third); // a copy of third // the iterator constructor can also be used to construct from arrays:
int myints[] = {,,,};
std::vector<int> fifth (myints, myints + sizeof(myints) / sizeof(int) ); std::cout << "The contents of fifth are:";
for (std::vector<int>::iterator it = fifth.begin(); it != fifth.end(); ++it)
std::cout << ' ' << *it;
std::cout << '\n'; return ;
}
参考
1.cplusplus.com-vector-construct;
完
【c++基础】vector初始化的几种方式的更多相关文章
- vector初始化的几种方式-STL
vector<int>::iterator int_ite; vector<string>::iterator string_ite; //vector<T> ...
- easyUI 初始化的两种方式
easyUI 初始化的两种方式: class方式和js方式: <!DOCTYPE html> <html lang="en"> <head> & ...
- 使用GoldenGate初始化的两种方式
在使用OGG开始增量数据的实时复制之前,一般需要对当前的存量数据进行初始化,如果是同构数据库,则可以使用数据库自带的工具完成,比如Oracle DB中的rman, expdp/impdp等. 其实og ...
- JavaScript 基础——使用js的三种方式,js中的变量,js中的输出语句,js中的运算符;js中的分支结构
JavaScript 1.是什么:基于浏览器 基于(面向)对象 事件驱动 脚本语言 2.作用:表单验证,减轻服务器压力 添加野面动画效果 动态更改页面内容 Ajax网络请求 () 3.组成部分:ECM ...
- WebApplicationContext初始化的两种方式和获取的三种方式
原博客地址:http://blog.csdn.net/lmb55/article/details/50510547 接下来以ContextLoaderListener为例,分析它到底做了什么? app ...
- java基础之 创建对象的几种方式
有4种显式地创建对象的方式: 1.用new语句创建对象,这是最常用的创建对象的方式. 2.运用反射手段,调用java.lang.Class或者java.lang.reflect.Constructor ...
- java数组初始化的三种方式
//第一种 int[] is= new int[3]; is[0]=1; is[1]=2; is[2]=3; //第二种 int[] is2= {1,2,3}; //第三种 int[] is3= ...
- java中String初始化的两种方式
转自:http://www.diybl.com/course/3_program/java/javajs/2007104/75886.html 字符串可能是任何程序语言中都会出现的对象,j ...
- jquery初始化的三种方式
第一种 $(document).ready(function(){ alert("第一种方法."); }); 第二种 $(function(){ alert("第二种方法 ...
随机推荐
- 正则表达式提取HTML中img标签的src地址
一般来说一个 HTML 文档有很多标签,比如“”.“”.“”等, 想把文档中的 img 标签提取出来并不是一件容易的事. 由于 img 标签样式变化多端,使提取的时候用程序寻找并不容易. 于是想要寻找 ...
- zlib__ZC
官网:http://www.zlib.net/ ,所有版本下载:http://www.zlib.net/fossils/ ZC: 我下载的是 zlib-1.2.3.tar.gz 和 zlib-1.2. ...
- [ios]cocos2dx获取设备的当前预言
参考:http://blog.sina.com.cn/s/blog_923fdd9b0101fmpv.html http://bbs.9ria.com/thread-199313-1-1.html / ...
- jdk1.8
Jdk1.8新特性 毫无疑问,Java 8是Java自Java 5(发布于2004年)之后的最重要的版本.这个版本包含语言.编译器.库.工具和JVM等方面的十多个新特性.在本文中我们将学习这些新特性, ...
- Codeforces 352B - Jeff and Periods
352B - Jeff and Periods 思路:水题,考验实现(implementation)能力,来一波vector[允悲]. 代码: #include<bits/stdc++.h> ...
- PHP函数笔记
一.函数(Function) 1.什么是函数:封装的,可以重复使用的 完成特定功能的代码段. 2.分类 (1)系统函数 (2)自定义函数 3.自定义函数 ...
- Enduring Exodus CodeForces - 655C (二分)
链接 大意: n个房间, 1为占用, 0为未占用, John要将k头奶牛和自己分进k+1个空房间, 求John距最远的奶牛距离的最小值 这种简单题卡了20min.... 显然对于固定的k+1个房间, ...
- uva-11426-数论
https://vjudge.net/problem/UVA-11426#author=0 求 SUM{ gcd(i,j) | 1<=i<j<=n}, n<4000001. 令 ...
- POJ-3087 Shuffle'm Up (模拟)
Description A common pastime for poker players at a poker table is to shuffle stacks of chips. Shuff ...
- Syntax error: Bad for loop variable解决办法
从 ubuntu 6.10 开始,ubuntu 就将先前默认的bash shell 更换成了dash shell:其表现为 /bin/sh 链接倒了/bin/dash而不是传统的/bin/bash. ...