#include <iostream>
#include <algorithm>
#include <vector>
int main() {
std::vector<int> vec = {1, 2, 2, 3, 3, 3, 4, 5, 6};
auto range = std::equal_range(vec.begin(), vec.end(), 3);
std::cout << "Range of values equal to 3: [" << (range.first - vec.begin()) << ", " << (range.second - vec.begin()) << ")" << std::endl;
return 0;
}
- Include Libraries: Include necessary C++ standard libraries.
- Main Function: Define the main function.
- Create Vector: Define a vector
vec
containing integers. - equal_range Function: Use
std::equal_range
to find the range of elements equal to the value 3
within the vector. - Output: Print the indices of the range where elements equal to
3
are found in the vector. - Return: End the main function and return 0 to indicate successful execution.