Syntax:
#include <set> pair<iterator, bool> set::insert(const TYPE& val); iterator set::insert(iterator pos, const TYPE& val); void set::insert(input_iterator start, input_iterator end);
The method insert() either:
For example, the following code uses insert to populate a set of integers:
const int max_nums = 10; int nums[max_nums] = {3,1,4,1,5,9,2,6,5,8}; set<int> digits; for( int i = 0; i < max_nums; ++i ) digits.insert(nums[i]); cout << "Unique digits are: "; for( set<int>::const_iterator iter = digits.begin(); iter != digits.end(); ++iter ) { cout << *iter << ' '; } cout << '\n';
When run, this code displays:
Unique digits are: 1 2 3 4 5 6 8 9