I have a question on the use of std::find() on a vector that contains
std::string objects.
When I need to do a search on a vector of strings, I currently use the
std::find() algorithm, e.g. :
std::vector<std::string>::iterator theIterator;
theIterator = std::find
(
vecStrings.begin(),
vecStrings.end(),
strToMatch
);
I then declare a global == operator :
bool operator == (const std::string& lhs, const std::stringr& rhs)
{
return (strcmp(lhs.c_str(), rhs.c_str()) == 0);
}
This works. But I need to know if this is the standard way of performing a
std::find() on a vector of std::strings.
Thanks, all,
- Bio.
You don't need to define `operator ==' for `std::string'. This
operator is already defined in <string> header. Otherwise, your
code is fine.
Alex
As the Standard headers include each other in unspecified ways, you should
always be careful to include the headers that you need.
Stephan T. Lavavej
Visual C++ Libraries Developer
"Alex Blekhman" <tkfx....@yahoo.com> wrote in message
news:uN1M9FpZ...@TK2MSFTNGP05.phx.gbl...