stl向量最大值
向量是什么? (What is the vector?)
Vector is a container in C++ STL, it is used to represent array and its size can be changed.
Vector是C ++ STL中的一个容器,用于表示数组,并且其大小可以更改。
Read more: C++ STL Vector
阅读更多: C ++ STL矢量
创建一个空向量 (Creating an empty vector)
Here is the syntax to declare an empty vector,
这是声明空向量的语法,
vector<type> vector_name;
Here,
这里,
type – is the datatype.
type –是数据类型。
vector_name – is any use defined name to the vector.
vector_name –是向量的任何使用定义的名称。
Example to create/declare an empty vector of int type
创建/声明一个int类型的空向量的示例
vector::<int> v1;
通过推元素初始化向量 (Initialize vector by pushing the element )
To insert an element in the vector, we can use vector::push_back() function, it inserts an element at the end of the vector.
要在向量中插入元素,我们可以使用vector :: push_back()函数,它将元素插入向量的末尾。
Syntax:
句法:
vector_name.push_back(element);
Example:
例:
v1.push_back(10);
v1.push_back(10);
.
.
C ++ STL程序创建空向量并通过推入值进行初始化 (C++ STL program to create an empty vector and initialize by pushing values)
//C++ STL program to create an empty vector
//and initialize by pushing values
#include <iostream>
#include <vector>
using namespace std;
int main()
{
//vector declaration
vector<int> v1;
//pushing the elements
v1.push_back(10);
v1.push_back(20);
v1.push_back(30);
v1.push_back(40);
v1.push_back(50);
//printing the vector elements
//creating iterator to access the elements
vector<int>::iterator it;
cout << "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/create-an-empty-vector-and-initialize-by-pushing-values.aspx
stl向量最大值