get index of value c++

To get the index of a value in C++, you can use the std::find algorithm from the <algorithm> header. Here are the steps to achieve this:

  1. Include the necessary header file: cpp #include <algorithm>

  2. Use the std::find algorithm to search for the value in the container: cpp auto it = std::find(container.begin(), container.end(), value);

  3. Check if the value was found: cpp if (it != container.end()) { // Value found, get the index int index = std::distance(container.begin(), it); } else { // Value not found }

These steps use the std::find algorithm to search for the value in the container and then determine the index if the value is found.