set cbegin() in C++

cbegin(): This function returns a read-only (constant) iterator that points to

 the first element in the set. 

Note: Iteration is done in ascending order according to the keys. 

This function is available in the below file.

File: stl_set.h

Parameters: No parameters are required for this function.

Syntax:

set<data_type>::const_iterator it =st.cbegin()

For Example:

st = {1,2,3,4}

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

Approach

C++

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

int main()
{
    set<intst;
    st.insert(4);
    st.insert(2);
    st.insert(3);
    st.insert(1);
    set<int>::const_iterator it = st.cbegin();

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

    return 0;
}


No comments:

Post a Comment