#include <iostream>
#include <map>
int main() {
std::map<int, std::string> myMap;
// Inserting elements into the map
myMap[1] = "One";
myMap[2] = "Two";
myMap[3] = "Three";
myMap[4] = "Four";
// Finding the index of an element in the map
int targetValue = 3;
auto it = std::find_if(myMap.begin(), myMap.end(),
[targetValue](const std::pair<int, std::string>& element) {
return element.second == std::to_string(targetValue);
});
// Checking if the element was found
if (it != myMap.end()) {
// Calculating the index using std::distance
int index = std::distance(myMap.begin(), it);
// Printing the index
std::cout << "Index of element with value " << targetValue << ": " << index << std::endl;
} else {
std::cout << "Element with value " << targetValue << " not found in the map." << std::endl;
}
return 0;
}