vector<int> intVector(, ); // Creates vector of 10 ints with value 100
vector<string> stringVector(, "hello");
vector<int> intVector3({ , , , , , });
vector<int> intVector1 = { , , , , , };
vector<int> intVector2{ , , , , , }; class Element
{
public:
Element() {}
virtual ~Element() {}
}; vector<Element> elementVector;
auto elementVector = make_unique<vector<Element>>();
vector<int> intVector();
// Other code . . .
intVector.assign(, );
intVector.assign({ , , , }); vector<int> vectorOne();
vector<int> vectorTwo(, );
vectorOne.swap(vectorTwo); vector<int> vectorOne();
vector<int> vectorTwo();
if (vectorOne == vectorTwo) {
cout << "equal!" << endl;
}
else {
cout << "not equal!" << endl;
}
vectorOne[] = ;
if (vectorOne < vectorTwo) {
cout << "vectorOne is less than vectorTwo" << endl;
}
else {
cout << "vectorOne is not less than vectorTwo" << endl;
} vector<double> doubleVector;
// Initialize max to smallest number
double max = -numeric_limits<double>::infinity();
for (size_t i = ; true; i++) {
double temp;
cout << "Enter score " << i << " (-1 to stop): ";
cin >> temp;
if (temp == -) {
break;
}
doubleVector.push_back(temp);
if (temp > max) {
max = temp;
}
}
max /= 100.0;
for (vector<double>::iterator iter = begin(doubleVector);
iter != end(doubleVector); ++iter) {
*iter /= max;
cout << *iter << " ";
} vector<string> stringVector(, "hello");
for (auto iter = cbegin(stringVector); iter != cend(stringVector); ++iter) {
cout << *iter << endl;
} vector<int> vectorOne = { , , , };
vector<int> vectorTwo;
// Oops, we forgot to add 4. Insert it in the correct place
vectorOne.insert(cbegin(vectorOne) + , );
// Add elements 6 through 10 to vectorTwo
for (int i = ; i <= ; i++) {
vectorTwo.push_back(i);
}
printVector(vectorOne);
printVector(vectorTwo);
// Add all the elements from vectorTwo to the end of vectorOne
vectorOne.insert(cend(vectorOne), cbegin(vectorTwo), cend(vectorTwo));
printVector(vectorOne);
// Now erase the numbers 2 through 5 in vectorOne
vectorOne.erase(cbegin(vectorOne) + , cbegin(vectorOne) + );
printVector(vectorOne);
// Clear vectorTwo entirely
vectorTwo.clear();
// And add 10 copies of the value 100
vectorTwo.insert(cbegin(vectorTwo), , );
// Decide we only want 9 elements
vectorTwo.pop_back();
printVector(vectorTwo); //The output of the program is as follows:
//1 2 3 4 5
//6 7 8 9 10
//1 2 3 4 5 6 7 8 9 10
//1 6 7 8 9 10
//100 100 100 100 100 100 100 100 100 vector<int> createVectorOfSize(size_t size)
{
vector<int> vec(size);
int contents = ;
for (auto& i : vec) {
i = contents++;
}
return vec;
}
...
vector<int> myVector;
myVector = createVectorOfSize(); class Element
{
public:
Element(int i, const string& str) : mI(i), mStr(str) {}
private:
int mI;
string mStr;
}; vector<Element> vec; Element myElement(, "Twelve");
vec.push_back(myElement);
vec.push_back(move(myElement));
vec.push_back(Element(, "Twelve"));
vec.push_back({, "Twelve"});
vec.emplace_back(, "Twelve");
vec.push_back({, "Twelve"});
// Or
vec.emplace_back(, "Twelve");

C++ STL 助记1:vector的更多相关文章

  1. UVa 11991:Easy Problem from Rujia Liu?(STL练习,map+vector)

    Easy Problem from Rujia Liu? Though Rujia Liu usually sets hard problems for contests (for example, ...

  2. 标准模板库(STL)学习探究之vector容器

    标准模板库(STL)学习探究之vector容器  C++ Vectors vector是C++标准模板库中的部分内容,它是一个多功能的,能够操作多种数据结构和算法的模板类和函数库.vector之所以被 ...

  3. JVM指令集(指令码、助记符、功能描述)(转)

    JVM指令集(指令码.助记符.功能描述) 指令码 助记符 功能描述 0x00 nop 无操作 0x01 aconst_null 指令格式:  aconst_null 功能描述:  null进栈. 指令 ...

  4. 【分支结构】Jcc 的一些助记

    eax > ebx OF=0 SF=0 ZF=0 AF=0 PF=0 CF=0 eax = ebx OF=0 SF=0 ZF=1 AF=0 PF=1 CF=0 eax < ebx OF=0 ...

  5. [三] java虚拟机 JVM字节码 指令集 bytecode 操作码 指令分类用法 助记符

    说明,本文的目的在于从宏观逻辑上介绍清楚绝大多数的字节码指令的含义以及分类 只要认真阅读本文必然能够对字节码指令集有所了解 如果需要了解清楚每一个指令的具体详尽用法,请参阅虚拟机规范 指令简介 计算机 ...

  6. 金蝶KIS&K3助记码SQL数据库批量刷新

    金蝶KIS&K3助记码SQL数据库批量刷新 用的次数不多,就没有写入存储过程或者触发里面了,可以自行实现. 第一步选择对应账套的数据库,执行下面的命令,这个是一个函数. go if exist ...

  7. 非对称加密, 助记词, PIN, WIF

    一钱包 1.1非对称加密, 助记词, PIN, WIF, 地址 1.1.1 非对称加密算法 非对称加密算法, 加密与解密使用不同的KEY, 我们分别称为私钥与公钥,其中可以通过私钥生成公钥 在比特币中 ...

  8. [转]HD钱包的助记词与密钥生成原理

    本文转自:https://blog.csdn.net/opassf/article/details/79978047 区块链相关的话题持续发酵之时,应该不少人知道加密货币钱包,钱包是普通用户与加密货币 ...

  9. [转]简单科普私钥、地址、助记词、Keystore的区别

    本文转自:https://www.jianshu.com/p/d0a4a44685d3 很多人保管不好自己的虚拟财产,发生丢币的情况,很多都是因为不清楚私钥的概念. 私钥(Private Key) 比 ...

随机推荐

  1. Leetcode5:Longest Palindromic Substring@Python

    Given a string s, find the longest palindromic substring in s. You may assume that the maximum lengt ...

  2. 关于Java static 的学习心得

    static,大家都很熟悉.但是要说真的懂,那就很少了.(当然我也不是很懂,但不妨碍学习吗.) 首先,我认为static修饰的成员就是属于类本身的成员.如果你加了一个static修饰符,好吧,那就相当 ...

  3. java上传xls文件

    using System; using System.Collections.Generic; using System.Web; using System.Web.UI; using System. ...

  4. vim的树形菜单NERDTREE的设置

    网上比较好的一篇文章:http://coolshell.cn/articles/1679.html http://coolshell.cn/articles/11312.html 1.Vim安装NER ...

  5. Java:多态(向上转型)

    先来看一段代码: class BaseClass{          public int book = 6;          public void base(){         System. ...

  6. 使用TCPDF插件生成pdf以及pdf的中文处理

    目录(?)[+] 多种多样的pdf开发库 WKHTMLTOPDF 2FPDF 3TCPDF 中文问题   做了这么多年项目,以前只是在别人的项目中了解过PHP生成pdf文件,知道并不难,但是涉及到了p ...

  7. DotNet Core 1.0 集成 CentOS 开发与运行环境部署

    一.     DotNet Core 1.0 开发环境部署 操作系统安装 我们使用CentOS 7.2.1511版本. 安装libunwind库 执行:sudo yum install libunwi ...

  8. Visual Studio 2015激活码,Visual Studio 2015密钥

    微软刚刚为开发人员奉上了最新大礼Visual Studio 2015正式版.如果你是MSDN订阅用户,现在就可以去下载丰富的相关资源.如果你指向体验一把尝尝鲜,微软也是很慷慨的. Visual Stu ...

  9. SOA架构介绍和理解

    SOA架构介绍和理解 SOA的正确方法论及目标模型,其实SOA在实现架构落地上,需要考虑到对服务的组合,不断的重用现有的服务,让企业应用可以逐步集成,快速实现业务的迭代. 通过SOA架构分层将服务按照 ...

  10. 循序渐进Python3(十一) --3--  web之dom

    DOM                  文档对象模型(Document Object Model,DOM)是一种用于HTML和XML文档的编程接口.它给文档提供了一种结构化的表示方法,可以改变文档的 ...