   Some vector help [solved]
  Hi,So I'm trying to figure out how to find out what position a certain string has in a vector. Like:std::vector <std::string>v;v.push_back("a");v.push_back("b");v.push_back("c"); and I wanted to find out what position b had it would return 1, a 0 of course, etc. I can't come up with a good way to do this.Tyvm.[Edited by - mopos on May 25, 2006 8:35:40 AM]
#include <algorithm>#include <iostream>#include <iterator>#include <vector>int main(){std::vector< std::string > v;v.push_back("a");v.push_back("b");v.push_back("c");std::vector< std::string >::iterator index = std::find(v.begin(), v.end(), "b");if (index == v.end()){std::cout << "\"b\" was not found.\n";}else{std::cout << "\"b\" was found at index " << std::distance(v.begin(), index) << ".\n";}}Σnigma   ;Quote:Original post by Enigma *** Source Snippet Removed ***ΣnigmaThank you very much mate.   