概述
stl vector 函数
C ++ vector :: pop_back()函数 (C++ vector::pop_back() function)
vector::pop_back() is a library function of "vector" header, it is used to deletes an element from the end of the vector, it deletes the element from the back and returns void.
vector :: pop_back()是“ vector”头文件的库函数,用于从矢量末尾删除元素,从背面删除该元素并返回void。
Note: To use vector, include <vector> header.
注意:要使用向量,请包含<vector>标头。
Syntax of vector::pop_back() function
vector :: pop_back()函数的语法
vector::pop_back();
Parameter(s): none – it accepts nothing.
参数: 无 –不接受任何内容。
Return value: none – In returns nothing.
返回值: none – In不返回任何内容。
Example:
例:
Input:
vector<int> v1{10, 20, 30, 40, 50};
//removing elemenets
v1.pop_back();
//removes 50
v1.pop_back();
//removes 40
Output:
//if we print the values
v1: 10 20 30
C ++程序演示vector :: pop_back()函数的示例 (C++ program to demonstrate example of vector::pop_back() function)
//C++ STL program to demonstrate example of
//vector::pop_back() function
#include <iostream>
#include <vector>
using namespace std;
int main()
{
//vector declaration
vector<int> v1{ 10, 20, 30, 40, 50 };
//printing elements
cout << "v1: ";
for (int x : v1)
cout << x << " ";
cout << endl;
//removing elements
v1.pop_back();
v1.pop_back();
//printing elements
cout << "After removing elements..." << endl;
cout << "v1: ";
for (int x : v1)
cout << x << " ";
cout << endl;
return 0;
}
Output
输出量
v1: 10 20 30 40 50
After removing elements...
v1: 10 20 30
Reference: C++ vector::pop_back()
参考: C ++ vector :: pop_back()
翻译自: https://www.includehelp.com/stl/vector-pop_back-function-with-example.aspx
stl vector 函数
最后
以上就是落寞钢铁侠为你收集整理的stl vector 函数_vector :: pop_back()函数以及C ++ STL中的示例的全部内容,希望文章能够帮你解决stl vector 函数_vector :: pop_back()函数以及C ++ STL中的示例所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复