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. tomcat gzip compression not working for large js files

    solution 1: <Connector port="8080" protocol="HTTP/1.1" connectionTimeout=&quo ...

  2. @UniqueConstraint

    jedis UniqueConstraint定义在Table或SecondaryTable元数据里,用来指定建表时需要建唯一约束的列. 元数据属性说明: columnNames:定义一个字符串数组,指 ...

  3. android 下载文件,file的读写应用

    先看代码: public class MainActivity extends AppCompatActivity { String TAG = MainActivity.class.getCanon ...

  4. Java Annotation 注解

    java_notation.html div.oembedall-githubrepos { border: 1px solid #DDD; list-style-type: none; margin ...

  5. calculator

    #include <stdio.h> #include <stdlib.h> typedef enum { FALSE = , TRUE }BOOL; void calcula ...

  6. linux 学习7 用户管理相关文件 r

    7.1.用户配置文件 7.2.用户管理相关文件 7.3.用户管理命令 7.4.用户组管理命令 删除用户userdel [root@localhost ~]# userdel [-r] 用户名 //一定 ...

  7. Delphi2010 DataSnap入门

    DataSnap到了Delphi2010有了很大的变化,已经可以完全抛弃DCOM之类的东西了,在以前版本中建立一个DataSnap,需要使用DCOMConnection或者SockConnection ...

  8. Web前端开发:为何选择MVVM而非MVC

    在Web中充斥着所谓的MVC框架,而在我看来,因为一些关键性的技术原因,MVC在Web前端开发中根本无法使用(对的,是无法,而不是不该) 在Web中充斥着所谓的MVC框架,而在我看来,因为一些关键性的 ...

  9. I2C总线和S5PV210的I2C总线控制器

    一.什么是I2C通信协议? 1.物理接口:SCL + SDA (1)SCL(serial clock):时钟线,传输CLK信号,一般是I2C主设备向从设备提供时钟的通道. (2)SDA(serial ...

  10. Head First Html and CSS学习笔记之HTML

    初学前端开发,记录下自己的学习笔记. 第一章 认识HTML 1:关于HTML HTML是超文本标记语言(HyperText Markup Language)的缩写,用来建立网页的结构. 它只会根据标记 ...