
- The C Standard Library
- The C Standard Library
- The C++ Standard Library
- C++ Library - Home
- C++ Library - <fstream>
- C++ Library - <iomanip>
- C++ Library - <ios>
- C++ Library - <iosfwd>
- C++ Library - <iostream>
- C++ Library - <istream>
- C++ Library - <ostream>
- C++ Library - <sstream>
- C++ Library - <streambuf>
- C++ Library - <atomic>
- C++ Library - <complex>
- C++ Library - <exception>
- C++ Library - <functional>
- C++ Library - <limits>
- C++ Library - <locale>
- C++ Library - <memory>
- C++ Library - <new>
- C++ Library - <numeric>
- C++ Library - <regex>
- C++ Library - <stdexcept>
- C++ Library - <string>
- C++ Library - <thread>
- C++ Library - <tuple>
- C++ Library - <typeinfo>
- C++ Library - <utility>
- C++ Library - <valarray>
- The C++ STL Library
- C++ Library - <array>
- C++ Library - <bitset>
- C++ Library - <deque>
- C++ Library - <forward_list>
- C++ Library - <list>
- C++ Library - <map>
- C++ Library - <queue>
- C++ Library - <set>
- C++ Library - <stack>
- C++ Library - <unordered_map>
- C++ Library - <unordered_set>
- C++ Library - <vector>
- C++ Library - <algorithm>
- C++ Library - <iterator>
- C++ Programming Resources
- C++ Programming Tutorial
- C++ Useful Resources
- C++ Discussion
C++ Set Library - find Function
Description
It searches the container for an element equivalent to val and returns an iterator to it if found, otherwise it returns an iterator to set::end.
Declaration
Following are the ways in which std::set::find works in various C++ versions.
C++98
iterator find (const value_type& val) const;
C++11
const_iterator find (const value_type& val) const; iterator find (const value_type& val);
Return value
It returns an iterator to set::end.
Exceptions
If an exception is thrown, there are no changes in the container.
Time complexity
Time complexity depens on logarithmic.
Example
The following example shows the usage of std::set::find.
#include <iostream> #include <set> int main () { std::set<int> myset; std::set<int>::iterator it; for (int i = 1; i <= 10; i++) myset.insert(i*10); it = myset.find(40); myset.erase (it); myset.erase (myset.find(60)); std::cout << "myset contains:"; for (it = myset.begin(); it!=myset.end(); ++it) std::cout << ' ' << *it; std::cout << '\n'; return 0; }
The above program will compile and execute properly.
myset contains: 10 20 30 50 70 80 90 100
set.htm
Advertisements