vector begin() in C++

begin(): It returns the read or write an iterator that points to the first element of the vector.

Syntax:

iterator vecName.begin()

File: stl_vector.h

Example:

vec = {1,2,3,4}

iterator it = vec.begin() => it returns the iterator to the first element (i.e. 1)

Approach

C++

#include <bits/stdc++.h>
using namespace std;

int main()
{
    vector<intvec = {1345};

    vector<int>::iterator it = vec.begin();
    cout << *it << "\n";

    return 0;
}


No comments:

Post a Comment