1. vector<int> intVector(, ); // Creates vector of 10 ints with value 100
  2. vector<string> stringVector(, "hello");
  3. vector<int> intVector3({ , , , , , });
  4. vector<int> intVector1 = { , , , , , };
  5. vector<int> intVector2{ , , , , , };
  6.  
  7. class Element
  8. {
  9. public:
  10. Element() {}
  11. virtual ~Element() {}
  12. };
  13.  
  14. vector<Element> elementVector;
  15. auto elementVector = make_unique<vector<Element>>();
  16. vector<int> intVector();
  17. // Other code . . .
  18. intVector.assign(, );
  19. intVector.assign({ , , , });
  20.  
  21. vector<int> vectorOne();
  22. vector<int> vectorTwo(, );
  23. vectorOne.swap(vectorTwo);
  24.  
  25. vector<int> vectorOne();
  26. vector<int> vectorTwo();
  27. if (vectorOne == vectorTwo) {
  28. cout << "equal!" << endl;
  29. }
  30. else {
  31. cout << "not equal!" << endl;
  32. }
  33. vectorOne[] = ;
  34. if (vectorOne < vectorTwo) {
  35. cout << "vectorOne is less than vectorTwo" << endl;
  36. }
  37. else {
  38. cout << "vectorOne is not less than vectorTwo" << endl;
  39. }
  40.  
  41. vector<double> doubleVector;
  42. // Initialize max to smallest number
  43. double max = -numeric_limits<double>::infinity();
  44. for (size_t i = ; true; i++) {
  45. double temp;
  46. cout << "Enter score " << i << " (-1 to stop): ";
  47. cin >> temp;
  48. if (temp == -) {
  49. break;
  50. }
  51. doubleVector.push_back(temp);
  52. if (temp > max) {
  53. max = temp;
  54. }
  55. }
  56. max /= 100.0;
  57. for (vector<double>::iterator iter = begin(doubleVector);
  58. iter != end(doubleVector); ++iter) {
  59. *iter /= max;
  60. cout << *iter << " ";
  61. }
  62.  
  63. vector<string> stringVector(, "hello");
  64. for (auto iter = cbegin(stringVector); iter != cend(stringVector); ++iter) {
  65. cout << *iter << endl;
  66. }
  67.  
  68. vector<int> vectorOne = { , , , };
  69. vector<int> vectorTwo;
  70. // Oops, we forgot to add 4. Insert it in the correct place
  71. vectorOne.insert(cbegin(vectorOne) + , );
  72. // Add elements 6 through 10 to vectorTwo
  73. for (int i = ; i <= ; i++) {
  74. vectorTwo.push_back(i);
  75. }
  76. printVector(vectorOne);
  77. printVector(vectorTwo);
  78. // Add all the elements from vectorTwo to the end of vectorOne
  79. vectorOne.insert(cend(vectorOne), cbegin(vectorTwo), cend(vectorTwo));
  80. printVector(vectorOne);
  81. // Now erase the numbers 2 through 5 in vectorOne
  82. vectorOne.erase(cbegin(vectorOne) + , cbegin(vectorOne) + );
  83. printVector(vectorOne);
  84. // Clear vectorTwo entirely
  85. vectorTwo.clear();
  86. // And add 10 copies of the value 100
  87. vectorTwo.insert(cbegin(vectorTwo), , );
  88. // Decide we only want 9 elements
  89. vectorTwo.pop_back();
  90. printVector(vectorTwo);
  91.  
  92. //The output of the program is as follows:
  93. //1 2 3 4 5
  94. //6 7 8 9 10
  95. //1 2 3 4 5 6 7 8 9 10
  96. //1 6 7 8 9 10
  97. //100 100 100 100 100 100 100 100 100
  98.  
  99. vector<int> createVectorOfSize(size_t size)
  100. {
  101. vector<int> vec(size);
  102. int contents = ;
  103. for (auto& i : vec) {
  104. i = contents++;
  105. }
  106. return vec;
  107. }
  108. ...
  109. vector<int> myVector;
  110. myVector = createVectorOfSize();
  111.  
  112. class Element
  113. {
  114. public:
  115. Element(int i, const string& str) : mI(i), mStr(str) {}
  116. private:
  117. int mI;
  118. string mStr;
  119. };
  120.  
  121. vector<Element> vec;
  122.  
  123. Element myElement(, "Twelve");
  124. vec.push_back(myElement);
  125. vec.push_back(move(myElement));
  126. vec.push_back(Element(, "Twelve"));
  127. vec.push_back({, "Twelve"});
  128. vec.emplace_back(, "Twelve");
  129. vec.push_back({, "Twelve"});
  130. // Or
  131. 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. Nginx配置location总结及rewrite规则写法

    p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 32.0px "Helvetica Neue"; color: #323333 } p. ...

  2. SQL Server复制情况下的高可用方案(一)镜像+复制

    数据库镜像可以与事务复制一起使用实现数据库整体的高可用性和高性能,其中镜像可以提供故障检测和故障转移,复制则用于实现读写分离. 数据库镜像涉及一个数据库的两个副本,这两个副本通常驻留在不同的计算机上. ...

  3. arcgis对谷歌遥感影像拼接

    对于遥感影像的研究多种多样,有小尺度的也有大尺度的还有多尺度的.可以研究一个城市里的一个区,也可以研究一个省甚至全国范围.当研究的区域比较大的时候,在一幅影像上无法包括研究区的所有范围,那么就需要下载 ...

  4. Productivity Power Tools 动画演示(转)

    Productivity Power Tools 是微软官方推出的 Visual Studio 扩展,被用以提高开发人员生产率.它的出现一定程度上弥补和完善了 Visual Studio 自身的不足, ...

  5. python容器类型:列表,字典,集合等

    容器的概念我是从C++的STL中学到的 什么是容器? 容器是用来存储和组织其他对象的对象. 也就是说容器里面可以放很多东西,这些东西可以是字符串,可以是整数,可以是自定义类型,然后把这些东西有组织的存 ...

  6. Oracle 的递归查询将层级变成字符串

    select A.PARENT_GROUP_ID, A.GROUP_ID,sys_connect_by_path(A.GROUP_ID,'/') || '/' path from dam_dataen ...

  7. Bash Shell的操作环境

    1.路径与命令查找顺序 基本上,命令运行的顺序可以这样看: 1)以相对/绝对路径执行命令,例如“/bin/ls”或“./ls”; 2)由alias找到该命令来执行; 3)由bash内置的(builti ...

  8. RapidXML 试用

    近半年来断断续续的封装一些SDK,在兼顾跨平台.易用性和高效率上还要顾及到对外dll的大小问题.由于之前解析SVG文件的用到了一个XML解析库xercesc,这个DLL实在巨大近4M,于是尝试用新的X ...

  9. 学习C:打印输入中单词长度的水平方向直方图

    #include <stdio.h>#define IN 1#define OUT 0#define MAXWL 16 main() { /*打印输入单词长度的水平直方图*/ int c, ...

  10. shell编程学习

    1.项目中用到Linux的crontrab Linux下的定时执行主要是使用crontab文件中加入定制计划来执行,但是也不是非常复杂,基本上用过一遍就能记住了,关键是要记住/var/spool/cr ...