0

Suppose I define std::vector<std::string> names and I declare

names[0] = "John";
names[1] = "Patrick";
names[2] = "Carol";
names[3] = "Jessica";

Is there a method I can use to get the index of a certain name, e.g. names.gettheindex("John") would return the index 0?

Leo
  • 11
  • 4
  • 2
    [`std::find`](https://en.cppreference.com/w/cpp/algorithm/find) returns an iterator, whose [distance](https://en.cppreference.com/w/cpp/iterator/distance) from the [beginning](https://en.cppreference.com/w/cpp/container/vector/begin) will be the index. – Some programmer dude Mar 20 '21 at 19:41

0 Answers0