stl vector 函数_vector :: pop_back()函数以及C ++ STL中的示例
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 elemenetsv1.pop_back(); //removes 50v1.pop_back(); //removes 40Output://if we print the valuesv1: 10 20 30C ++程序演示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 declarationvector<int> v1{ 10, 20, 30, 40, 50 };//printing elementscout << "v1: ";for (int x : v1)cout << x << " ";cout << endl;//removing elementsv1.pop_back();v1.pop_back();//printing elementscout << "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 30Reference: 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中的示例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 詹姆斯多少钱啊?
- 下一篇: 现在一黄金多少钱一克啊?