C++ STL 助记1:vector
- 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的更多相关文章
- 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, ...
- 标准模板库(STL)学习探究之vector容器
标准模板库(STL)学习探究之vector容器 C++ Vectors vector是C++标准模板库中的部分内容,它是一个多功能的,能够操作多种数据结构和算法的模板类和函数库.vector之所以被 ...
- JVM指令集(指令码、助记符、功能描述)(转)
JVM指令集(指令码.助记符.功能描述) 指令码 助记符 功能描述 0x00 nop 无操作 0x01 aconst_null 指令格式: aconst_null 功能描述: null进栈. 指令 ...
- 【分支结构】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 ...
- [三] java虚拟机 JVM字节码 指令集 bytecode 操作码 指令分类用法 助记符
说明,本文的目的在于从宏观逻辑上介绍清楚绝大多数的字节码指令的含义以及分类 只要认真阅读本文必然能够对字节码指令集有所了解 如果需要了解清楚每一个指令的具体详尽用法,请参阅虚拟机规范 指令简介 计算机 ...
- 金蝶KIS&K3助记码SQL数据库批量刷新
金蝶KIS&K3助记码SQL数据库批量刷新 用的次数不多,就没有写入存储过程或者触发里面了,可以自行实现. 第一步选择对应账套的数据库,执行下面的命令,这个是一个函数. go if exist ...
- 非对称加密, 助记词, PIN, WIF
一钱包 1.1非对称加密, 助记词, PIN, WIF, 地址 1.1.1 非对称加密算法 非对称加密算法, 加密与解密使用不同的KEY, 我们分别称为私钥与公钥,其中可以通过私钥生成公钥 在比特币中 ...
- [转]HD钱包的助记词与密钥生成原理
本文转自:https://blog.csdn.net/opassf/article/details/79978047 区块链相关的话题持续发酵之时,应该不少人知道加密货币钱包,钱包是普通用户与加密货币 ...
- [转]简单科普私钥、地址、助记词、Keystore的区别
本文转自:https://www.jianshu.com/p/d0a4a44685d3 很多人保管不好自己的虚拟财产,发生丢币的情况,很多都是因为不清楚私钥的概念. 私钥(Private Key) 比 ...
随机推荐
- Nginx配置location总结及rewrite规则写法
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 32.0px "Helvetica Neue"; color: #323333 } p. ...
- SQL Server复制情况下的高可用方案(一)镜像+复制
数据库镜像可以与事务复制一起使用实现数据库整体的高可用性和高性能,其中镜像可以提供故障检测和故障转移,复制则用于实现读写分离. 数据库镜像涉及一个数据库的两个副本,这两个副本通常驻留在不同的计算机上. ...
- arcgis对谷歌遥感影像拼接
对于遥感影像的研究多种多样,有小尺度的也有大尺度的还有多尺度的.可以研究一个城市里的一个区,也可以研究一个省甚至全国范围.当研究的区域比较大的时候,在一幅影像上无法包括研究区的所有范围,那么就需要下载 ...
- Productivity Power Tools 动画演示(转)
Productivity Power Tools 是微软官方推出的 Visual Studio 扩展,被用以提高开发人员生产率.它的出现一定程度上弥补和完善了 Visual Studio 自身的不足, ...
- python容器类型:列表,字典,集合等
容器的概念我是从C++的STL中学到的 什么是容器? 容器是用来存储和组织其他对象的对象. 也就是说容器里面可以放很多东西,这些东西可以是字符串,可以是整数,可以是自定义类型,然后把这些东西有组织的存 ...
- Oracle 的递归查询将层级变成字符串
select A.PARENT_GROUP_ID, A.GROUP_ID,sys_connect_by_path(A.GROUP_ID,'/') || '/' path from dam_dataen ...
- Bash Shell的操作环境
1.路径与命令查找顺序 基本上,命令运行的顺序可以这样看: 1)以相对/绝对路径执行命令,例如“/bin/ls”或“./ls”; 2)由alias找到该命令来执行; 3)由bash内置的(builti ...
- RapidXML 试用
近半年来断断续续的封装一些SDK,在兼顾跨平台.易用性和高效率上还要顾及到对外dll的大小问题.由于之前解析SVG文件的用到了一个XML解析库xercesc,这个DLL实在巨大近4M,于是尝试用新的X ...
- 学习C:打印输入中单词长度的水平方向直方图
#include <stdio.h>#define IN 1#define OUT 0#define MAXWL 16 main() { /*打印输入单词长度的水平直方图*/ int c, ...
- shell编程学习
1.项目中用到Linux的crontrab Linux下的定时执行主要是使用crontab文件中加入定制计划来执行,但是也不是非常复杂,基本上用过一遍就能记住了,关键是要记住/var/spool/cr ...