set::begin() and set::end() in C++ STL

C++Server Side ProgrammingProgramming

Set::begin() function is a bidirectional iterator used to return an iterator pointing to the first element of the set container.

Set::end() function is a bidirectional iterator used to return an iterator pointing to the last element of the set container.

Example Code

 Live Demo

#include<iostream>
#include <bits/stdc++.h>
using namespace std;
int main() {
   set<int> s;
   set<int>::iterator it;
   s.insert(7);
   s.insert(6);
   s.insert(1);
   s.insert(4);
   s.insert(2);
   s.insert(9);
   s.insert(10);
   for (auto it=s.begin(); it != s.end(); ++it)
      cout << ' ' << *it;
   return 0;
}

Output

1 2 4 6 7 9 10
raja
Published on 02-Apr-2019 17:45:22
Advertisements