set::insert() function in C++ STL

In C++, the standard library gives us the facility to use the Sets as a type of associative containers in which each element has to be unique. The set::insert() is a C++ Standard Library function which is used to insert an element to the set container. After every insertion, the size of set increased by 1.


Set_Name.insert( Element );

Parameter: The set::insert() function accepts only single parameter:

  • Element: This parameter is the element to be inserted in the set container.

Return value: The set::insert() function returns the iterator pointing to the inserted element.

Example of set::insert() Function

#include <bits/stdc++.h> 
using namespace std; 
int main() 

    set<int> SET; 
    auto val = SET.find(3); 
    if (val != SET.end())
        cout << "Element Found"; 
        cout << "Element Not Found"; 
    return 0; 


Element Not Found

This article is written by

Pratik Singhal

Pratik Singhal

Please comment below, if you have any doubts or find any error in the above article.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top
[gravityforms id="5" description="false" titla="false" ajax="true"]