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.

我们从第一个元素到小于过去的元素运行一个循环,并打印矢量元素。

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 iterator
    vector<int>::iterator it;

    //printing all elements
    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/printing-all-elements-of-a-vector-using-vector-begin-and-vector-end-functions.aspx

stl vector 函数

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值