C++ set

Introduction

Set is a container that holds unique, sorted objects.

It is a binary tree of sorted objects.

To use a set, we must include the <set> header.

To define a set we use the std::set<type> set_name syntax.

To initialize a set of 5 integers, we can write:

#include <iostream> 
#include <set> 

int main() //from  ww w.j  a v a  2  s. c o  m
{ 
    std::set<int> myset = { 1, 2, 3, 4, 5 }; 
    for (auto el : myset) 
    { 
        std::cout << el << '\n'; 
    } 
} 



PreviousNext

Related