Fast search of a vector of strings
-
Hello, I have the following code that searches a list of wchar_t * strings. What I want is a function like this: vector paths; find (paths.begin(), paths.end(), L"some string"); What do I need to do to get this to return the string I'm searching for? - BRC
-
Hello, I have the following code that searches a list of wchar_t * strings. What I want is a function like this: vector paths; find (paths.begin(), paths.end(), L"some string"); What do I need to do to get this to return the string I'm searching for? - BRC
This will not return a string but an iterator to the matching string. Your code would look something like this.
bool Comparer : public std::binary_function<wchar_t*, wchar_t*,bool>
{
public:
bool operator()(const wchar_t* s1, const wchar_t* s2) const
{
return (wcscmp(s1, s2) == 0);
}
};std::vector<wchar_t*> paths;
std::vector<wchar_t*>::const_iterator it;it = std::find_if(paths.begin(), paths.end(), std::bind2nd(Comparer(), L"some string"));
if (it != paths.end())
{
/*Found it*
const wchar_t* sz = *it;
}...
Pax Domini sit semper vobiscum