日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

發布時間:2023/12/1 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 stl vector 函数_vector :: push_back()函数,以及C ++ STL中的示例 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

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 valuesv1: 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 declarationvector<int> v1;//inserting elements and printing sizecout << "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 elementscout << "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中的示例的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。