stl向量最大值_创建一个空向量并通过在C ++ STL中推送值进行初始化

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向量最大值

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值