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) 比 ...
随机推荐
- VideoToolbox硬件编解码H.264视频流错误码
如果你不能找到在VTD中的错误代码我决定只包括他们在这里. (同样,所有这些错误,并更可以在里面VideoToolbox在Project Navigator中找到.本身). 您将获得无论是在VTD中 ...
- Centos安装jdk
运行Java应用的时候,提示无法找到JAVA_HOME,查询java -version [jifeng@localhost bin]$ java -version java version " ...
- bind9+mysql dlz(Dynamically Loadable Zones)
yum install openssl openssl-devel groupadd mysqluseradd -g mysql -s /sbin/nologin -M mysqlchown -R m ...
- 8.31 js基础总结1
JavaScript是一种脚本语言,由web浏览器进行解释和执行.它给予页面灵魂,让页面可以动起来,包括动态的数据,动态的标签,动态的样式等等. 将JavaScript应用到网页中常用的方法有两种,第 ...
- Android代码故事第一回,平均间隔的按钮
我们的APP新做了一个放操作按钮的界面,老板要求简洁美观有内涵,按钮要均匀分布,于是参考之前的实现,设计MM给了一张图,像这样: |================================== ...
- linux 驱动学习笔记05--文件系统与设备文件系统
查看/proc/devices 文件可以获知系统中注册的设备,第 1 列为主设备号,第 2 列为设备名,如:
- Linux下的tar压缩解压缩命令详解
转载自http://www.cnblogs.com/qq78292959/archive/2011/07/06/2099427.html tar -c: 建立压缩档案-x:解压-t:查看内容-r:向压 ...
- VC++ 两种动态调整控件位置的方法(CButton设置为Radio形式会出现错误)
((CButton*)GetDlgItem(IDC_CHECK1))->MoveWindow(, cy - , , ); ((CButton*)GetDlgItem(IDC_CHECK2))-& ...
- CentOS 7 安装 MySQL
转自:http://www.centoscn.com/mysql/2016/0315/6844.html 环境 CentOS 7.1 (64-bit system) MySQL 5.6.24 Cent ...
- 安装oracle ebs 出现问题 atleast 55M of disk space
出现这个问题 可以进行如下尝试: 1.登陆用户是否具有管理员权限,可以右击exe用管理员登陆. 2.安装电脑是否有安装mcafee,可以禁用后运行. 3.看下C:\Documents and Sett ...