vector cbegin() in C++

cbegin(): It returns the read-only (constant) iterator that points to the first element

in the vector.

Syntax:

vector<data_type> ::const_iterator iteratorName = vecName.cbegin()

File: stl_vector.h

For Example:

vec = {1,2,3,4}

vec.cbegin() => It returns the iterator to first element (i.e 1)

Approach

C++

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

int main()
{
    vector<intvec = {1345};
    vector<int>::const_iterator it = vec.cbegin();

    cout << *it << "\n";

    return 0;
}


No comments:

Post a Comment