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. 16.C语言中数据类型的本质含义是:表示一个内存格子的长度和解析方法。

    数据类型决定长度的含义:我们一个内存地址(0x30000000),本来这个地址只代表1个字节的长度,但是实际上我们可以通过给他一个类型(int),让他有了长度(4),这样这个代表内存地址的数字(0x3 ...

  2. 标准bootstrap html 页面

    <!DOCTYPE html><html lang="zh-cn"><head> <meta charset="utf-8&qu ...

  3. 仿微软控件的html元素

    <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head>     & ...

  4. zookeeper+dubbo集群

    1.https://no-east.gitbooks.io/origin-zookeeper/content/zookeeper_gong_zuo_yuan_li.html 2.http://blog ...

  5. heartbeat重要文件的配置参数说明

    主要三个重要的文件:ha.cf, authkey, haresource 1)ha.cf的重要参数的说明: 参数 说明 debugfile  /var/log/ha-debug           h ...

  6. 代理服务器(Proxy)原理

    17.1 什么是代理服务器(Proxy)   以类似代理人的身份去取得用户所需要的数据就是了! 但是由于它的『代理』能力,使得我们可以透过代理服务器来达成防火墙功能与用户浏览数据的分析!   此外,也 ...

  7. ajax同步异步问题

    之前一直在写JQUERY代码的时候遇到AJAX加载数据都需要考虑代码运行顺序问题.最近的项目用了到AJAX同步.这个同步的意思是当JS代码加载到当前AJAX的时候会把页面里所有的代码停止加载,页面出去 ...

  8. Android 之Html的解析(使用jsoup)

    Runnable run=new Runnable() { @Override public void run() { // TODO Auto-generated method stub useri ...

  9. [转] --- Error: “A field or property with the name was not found on the selected data source” get only on server

    Error: “A field or property with the name was not found on the selected data source” get only on ser ...

  10. 《IT蓝豹》完整阅读软件客户端app

    完整阅读软件客户端app,本项目里面还有扫描功能,搜索本地书籍,不过扫码功能通过c++层实现的. 本项目来自:https://github.com/JayFang1993/ScanBook Captu ...