The `std::multimap::equal_range` function is used to determine the range of elements with a given key in a multimap. It returns a pair of iterators that represent the starting and ending point of the range.
Example 1: Finding the range of elements with a given key in a multimap
#include
#include
In this example, we create a `std::multimap` that maps integers to strings. We then use `equal_range` to find the range of elements with a key value of 1. We iterate over the range using the iterators returned by `equal_range`, and print the corresponding strings. The output of this program will be:
apple
banana
This example uses the C++ standard library.
Example 2: Finding the range of elements with a struct key in a multimap
#include
#include
In this example, we use a `struct` called `Fruit` as the key type for our `std::multimap`. We define the `<` operator for `Fruit` so that we can compare them based on their price. We then create a `std::multimap` that maps `Fruit` keys to integers.
We create a `Fruit` object called `key` with a name of "apple" and a price of 0.5. We then use `equal_range` to find the range of elements with `key`. We iterate over the range using the iterators returned by `equal_range`, and print the corresponding integers. The output of this program will be:
10
The `std::multimap::equal_range` function is part of the C++ standard library.
C++ (Cpp) multimap::equal_range - 30 examples found. These are the top rated real world C++ (Cpp) examples of std::multimap::equal_range extracted from open source projects. You can rate examples to help us improve the quality of examples.