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.
Syntax
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; SET.insert(10); SET.insert(4); SET.insert(12); SET.insert(15); auto val = SET.find(3); if (val != SET.end()) { cout << "Element Found"; } else { cout << "Element Not Found"; } return 0; }
Output
Element Not Found