J
Joe
I have a: vector<string> which contains a few dozen elements.
I want to find the index of the element containing a certain string.
for example:
vector<string> strings;
strings.push_back("abc");
strings.push_back("xyz");
strings.push_back("lmnop");
int index = distance(strings.begin(), find(strings.begin(),
strings.end(), string("xyz")));
cout << index << endl; // should print out a '1', the index of "xyz"
The above line using 'distance' seems pretty terrible to me. Please
tell me that there a better way?
Thanks in advance,
Joe
I want to find the index of the element containing a certain string.
for example:
vector<string> strings;
strings.push_back("abc");
strings.push_back("xyz");
strings.push_back("lmnop");
int index = distance(strings.begin(), find(strings.begin(),
strings.end(), string("xyz")));
cout << index << endl; // should print out a '1', the index of "xyz"
The above line using 'distance' seems pretty terrible to me. Please
tell me that there a better way?
Thanks in advance,
Joe