C++ set begin()C++ set begin() function is used to return an iterator referring to the first element of the set container. SyntaxParameterNone Return valueIt returns an iterator pointing to the first element of the set. ComplexityConstant. Iterator validityNo changes. Data RacesThe container is accessed. Neither the constant nor the non-constant versions modify the container. Exception SafetyThis function never throws exceptions. Example 1Let's see the simple example for begin() function: Output: Contents of myset are: C++ Java SQL In the above example, begin() function is used to return an iterator pointing to the first element in the myset set. Example 2Let's see a simple example: Output: 0 1 2 4 5 9 Example 3Let's see a simple example to iterate over the set using while loop: Output: Elements of myset are: Aman Deep Nikita Priya Suman In the above, begin() function is used to return an iterator pointing to the first element in the myset set. Example 4Let's see a simple example: Output: The first element of s1 is 1 The first element of s1 is now 2 In the above example, begin() function is used to return an iterator pointing to the first element in the myset set.
Next TopicSet cbegin() Function
|