Algorithm 🧑🏻‍💻/Note

[C++, 템플릿] map find index

dkswnkk 2022. 8. 23. 22:17

Get index of element in C++ map

 

Get index of element in C++ map

I have a std::map called myMap in my C++ application, and I want to get an element using either myMap.find(key) or myMap[key]. However, I would also like to get the index of that element in the map...

stackoverflow.com

int k = distance(mymap.begin(), mymap.find(mykey));
저작자표시 (새창열림)