index of a found string element of a vector using find function

How can I find the position of an element in the vector I am searching the element in for?
Last edited on
Perhaps something like:

1
2
3
4
5
6
const auto itr {std::find(vect.begin(), vect.end(), tofind)};

if (itr != vect.end())
    std::cout << "Found at position " << std::distance(vect.begin(), itr) << '\n';
else
    std::cout << "Not found\n";

Topic archived. No new replies allowed.