stl vector 函数
C ++ vector :: begin()函数 (C++ vector::begin() function)
vector::begin() is a library function of "vector" header, it is used to get the first element of a vector. It returns an iterator pointing to the first element of the vector.
vector :: begin()是“ vector”标头的库函数,用于获取矢量的第一个元素。 它返回指向向量的第一个元素的迭代器。
Note: To use vector, include <vector> header.
注意:要使用向量,请包含<vector>标头。
Syntax of vector::begin() function
vector :: begin()函数的语法
vector::begin();
Parameter(s): none – It accepts nothing.
参数: 无 –不接受任何内容。
Return value: iterator – It returns an iterator pointing to the first element of the vector.
返回值: iterator –返回指向向量的第一个元素的迭代器。
Example:
例:
Input:
vector<int> vector1{ 1, 2, 3, 4, 5 };
Function call:
vector<int>::iterator it;
it = vector1.begin();
cout << *it;
Output:
1
C ++ STL程序演示vector :: begin()函数的示例 (C++ STL program to demonstrate example of vector::begin() function)
//C++ STL program to demonstrate example of
//vector::begin() function
#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 iterator
vector<int>::iterator it;
it = v1.begin();
cout << "first element is: " << *it << endl;
return 0;
}
Output
输出量
first element is: 10
Reference: C++ vector::begin()
翻译自: https://www.includehelp.com/stl/vector-begin-function-with-example.aspx
stl vector 函数