Or login with:
#include <set> namespace std { template < class T, class Compare = less<T>, class Allocator = allocator<T> > class set; }
set<string> setStr; // declar a string set| Operation | Effect |
|---|---|
| set s | Creates an empty set without any elements |
| set s(op) | Creates an empty set that uses op as the sorting criterion |
| set s1(s2) | Creates a copy of another set of the same type (all elements are copied) |
| set s(beg,end) | Creates a set initialized by the elements of the range [beg,end) |
| set s(beg,end, op) | Creates a set with the sorting criterion op initialized by the elements of the range [beg,end) |
| s.~set() | Destroys all elements and frees the memory |
| Set | Effect |
|---|---|
| set<el> | A set that sorts with less<> (operator <) |
| set<el,op> | A set that sorts with op |
| Operation | Effect |
|---|---|
| s.size() | Returns the number of elements |
| s.empty() | Returns if the container is empty (equivalent to size()==0) |
| s.max_size() | Returns the maximum number of elements possible |
| s1==s2 | Returns if s1 is equal to s2 |
| s1!=s2 | Returns if s1 is not equal to s2 (equivalent to !(s1==s2)) |
| s1<s2 | Returns if s1 is less than s2 |
| s1>s2 | Returns if s1 is greater than s2 (equivalent to s2<s1) |
| s1<=s2 | Returns if s1 is less than or equal to s2 (equivalent to !(s2<s1)) |
| s1>=s2 | Returns if s1 is greater than or equal to s2 (equivalent to !(s1<s2)) |
| Operation | Effect |
|---|---|
| count(el) | Returns the number of elements with value el |
| find(el) | Returns the position of the first element with value el or end() |
| lower_bound(el) | Returns the first position, where el would get inserted (the first element >= el) |
| upper_bound(el) | Returns the last position, where el would get inserted (the first element > el) |
| equal_range(el) | Returns the first and last position, where el would get inserted (the range of elements == el) |
| Operation | Effect |
|---|---|
| s1=s2 | Assigns all elements of s2 to s1 |
| s1.swap(s2) | Swaps the data of s1 and s2 |
| swap(s1,s2) | Same (as global function) |
| Operation | Effect |
|---|---|
| s.begin() | Returns a bidirectional iterator for the first element (elements are considered const) |
| s.end() | Returns a bidirectional iterator for the position after the last element (elements are considered const) |
| s.rbegin() | Returns a reverse iterator for the first element of a reverse iteration |
| s.rend() | Returns a reverse iterator for the position after the last element of a reverse iteration |
| Operation | Effect |
|---|---|
| s.insert(el) | Inserts a copy of el and returns the position of the new element and if it succeeded |
| s.insert(pos, el) | Inserts a copy of el and returns the position of the new element (pos is used as a hint pointing to where the insert should start the search) |
| s.insert(beg,end) | Inserts a copy of all elements of the range [beg,end) (returns nothing) |
| s.erase(el) | Removes all elements with value el and returns the number of removed elements |
| s.erase(pos) | Removes the element at iterator position pos (returns nothing) |
| s.erase(beg,end) | Removes all elements of the range [beg,end) (returns nothing) |
| s.clear() | Removes all elements |
#include <iostream> #include <algorithm> #include <iterator> #include <set> using namespace std; int main() { double s[5]={1.0, 4.4, 67.1, 1.0, 23.7, 67.1}; std::set< double, std::less<double> > ds(s, s+5); std::ostream_iterator< double > output( cout, " " ); cout <<"The set contains: "; std::copy(ds.begin(), ds.end(), output); cout <<endl; return 0; }
You must login to leave a messge