stl vector 函数_在C ++ STL中使用vector :: begin()和vector :: end()函数打印矢量的所有元素...
stl vector 函數
打印向量的所有元素 (Printing all elements of a vector)
To print all elements of a vector, we can use two functions 1) vector::begin() and vector::end() functions.
要打印矢量的所有元素,我們可以使用兩個函數:1) vector :: begin()和vector :: end()函數。
vector::begin() function returns an iterator pointing to the first elements of the vector.
vector :: begin()函數返回一個指向向量的第一個元素的迭代器。
vector::end() function returns an iterator point to past-the-end element of the vector.
vector :: end()函數將迭代器點返回到向量的past-the-end元素。
We run a loop from the first element to the less than past-the-element and prints the vector elements.
我們從第一個元素到小于過去的元素運行一個循環(huán),并打印矢量元素。
Note: To use vector, include <vector> header.
注意:要使用向量,請包含<vector>標頭。
C ++ STL程序打印矢量的所有元素 (C++ STL program to print all elements of a vector)
//C++ STL program to print all elements of a vector #include <iostream> #include <vector> using namespace std;int main() {vector<int> v1;v1.push_back(10);v1.push_back(20);v1.push_back(30);v1.push_back(40);v1.push_back(50);//creating iteratorvector<int>::iterator it;//printing all elementscout << "vector v1 elements are: ";for (it = v1.begin(); it != v1.end(); it++)cout << *it << " ";cout << endl;return 0; }Output
輸出量
vector v1 elements are: 10 20 30 40 50翻譯自: https://www.includehelp.com/stl/printing-all-elements-of-a-vector-using-vector-begin-and-vector-end-functions.aspx
stl vector 函數
總結
以上是生活随笔為你收集整理的stl vector 函数_在C ++ STL中使用vector :: begin()和vector :: end()函数打印矢量的所有元素...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 颐和园门票退改规则
- 下一篇: oppo要多少钱啊?