stl vector 函数

C ++ vector :: push_back()函数 (C++ vector::push_back() function)

vector::push_back() is a library function of "vector" header, it is used to insert/add an element at the end of the vector, it accepts an element of the same type and adds the given element at the end of the vector and increases the size of the vector.

vector :: push_back()“ vector”标头的库函数,用于在vector的末尾插入/添加元素,它接受相同类型的元素并在给定的末尾添加给定元素向量并增加向量的大小。

Note: To use vector, include <vector> header.

注意:要使用向量,请包含<vector>标头。

Syntax of vector::push_back() function

vector :: push_back()函数的语法

    vector::push_back(value_type n);

Parameter(s): n – is an element to be added at the end of the vector.

参数: n –是要在向量末尾添加的元素。

Return value: void – In returns nothing.

返回值: void – In不返回任何内容。

Example:

例:

    Input:
vector<int> v1;
v1.push_back(20);
v1.push_back(30);
v1.push_back(40);
v1.push_back(50);
Output:
//if we print the values
v1: 20 30 40 50

C ++程序演示vector :: push_back()函数的示例 (C++ program to demonstrate example of vector::push_back() function)

//C++ STL program to demonstrate example of
//vector::push_back() function
#include <iostream>
#include <vector>
using namespace std;
int main()
{//vector declaration
vector<int> v1;
//inserting elements and printing size
cout << "size of v1: " << v1.size() << endl;
v1.push_back(10);
cout << "size of v1: " << v1.size() << endl;
v1.push_back(20);
v1.push_back(30);
v1.push_back(40);
v1.push_back(50);
cout << "size of v1: " << v1.size() << endl;
//printing all elements
cout << "elements of vector v1..." << endl;
for (int x : v1)
cout << x << " ";
cout << endl;
return 0;
}

Output

输出量

size of v1: 0
size of v1: 1
size of v1: 5
elements of vector v1...
10 20 30 40 50

Reference: C++ vector::push_back()

参考: C ++ vector :: push_back()

翻译自: https://www.includehelp.com/stl/vector-push_back-function-with-example.aspx

stl vector 函数

stl vector 函数_vector :: push_back()函数,以及C ++ STL中的示例相关推荐

  1. C++的string类型中关于append函数、push_back函数和+=运算符的区别

    部分内容翻译自 https://www.geeksforgeeks.org/stdstringappend-vs-stdstringpush_back-vs-operator-c/?ref=lbp 引 ...

  2. stl swap函数_C ++ STL | vector :: swap()函数与示例

    stl swap函数 C ++ STL vector :: swap()函数 (C++ STL vector::swap() function) vector::swap() function is ...

  3. matlab中now函数_now()方法以及JavaScript中的示例

    matlab中now函数 JavaScript now()方法 (JavaScript now() method) now() method is a Date class method, it is ...

  4. stl vector 函数_vector :: back()函数以及C ++ STL中的示例

    stl vector 函数 C ++ vector :: back()函数 (C++ vector::back() function) vector::back() is a library func ...

  5. stl vector 函数_vector :: at()函数以及C ++ STL中的示例

    stl vector 函数 C ++ vector :: at()函数 (C++ vector::at() function) vector::at() is a library function o ...

  6. stl vector 函数_vector :: crend()函数以及C ++ STL中的示例

    stl vector 函数 C ++ vector :: crend()函数 (C++ vector::crend() function) vector::crend() is a library f ...

  7. stl vector 函数_vector :: pop_back()函数以及C ++ STL中的示例

    stl vector 函数 C ++ vector :: pop_back()函数 (C++ vector::pop_back() function) vector::pop_back() is a ...

  8. stl vector 函数_vector :: clear()函数,以及C ++ STL中的示例

    stl vector 函数 C ++ vector :: clear()函数 (C++ vector::clear() function) vector::clear() is a library f ...

  9. stl vector 函数_vector :: crbegin()函数,以及C ++ STL中的示例

    stl vector 函数 C ++ vector :: crbegin()函数 (C++ vector::crbegin() function) vector::crbegin() is a lib ...

最新文章

  1. zabbix 系统搭建(LAMP环境)+keepalived LVS配置
  2. 基于FPGA的UART接口协议设计
  3. DataTable添加行的方法
  4. SAP UI5 Currency 数据类型的校验逻辑分析
  5. network怎么断点调试_Windows 网络编程:调试 API
  6. 安全成Win10进军企业级市场的最大卖点?
  7. GridView 设置背景透明以及Item的点击动画
  8. C++ stack(STL stack)
  9. 三维全景地图是怎么实现的?三维全景图制作教程
  10. org.apache.batik.transcoder.TranscoderException: null
  11. 游戏王怪兽胶囊Android,游戏王怪兽胶囊GB是什么?
  12. js获取本周日期和上周日期 --- 随手记录备忘
  13. unity关于中文字体显示问题
  14. 科目二需要注意的点(笔记包含图片讲解)
  15. mysql存储函数中游标报错 No data - zero rows fetched, selected
  16. 高数 | 为什么f(x)从a到b的积分等于从b到a的积分的相反数?
  17. GSL(C数学运算库)安装和使用教程
  18. 衡水二中2021年高考成绩查询,2020衡水二中高考喜报
  19. RPM的制作(.spec文件)
  20. 如何选择聚合支付平台

热门文章

  1. java的设计模式用的什么软件_《图解Java多线程设计模式》UML用什么软件画?
  2. java调用jndi出错,无法使用Java JNDI上下文查找来访问对象
  3. material 项目_Web开发必备的 10 个开源项目,不用自己亲自造轮子!
  4. mysql主键和聚簇索引_[MySQL] innoDB引擎的主键与聚簇索引
  5. js-原始类型和声明变量
  6. 记录一次cookie导致登录失败的惨案
  7. bzoj 2007 [Noi2010]海拔——最小割转最短路
  8. django F和Q 关键字使用
  9. yaml,json,ini这三种格式用来做配置文件优缺点
  10. Eclipse安装TestNG插件