std::count for strings?

Hey guys, I am rather new to using the C++ STL, and I would like some help with the std::count function. I have a list that contains strings, and I would like to make a function that counts the number a string repeats itself in the list...

Now, I was reading about the std::count function, and all examples are showing it counting the number of integers are in a list. I was wondering if it is possible to use that function to count how many times a string is repeated.


Here is the way I wrote the function:

int cWaitingLine::m_FindRepeats( std::string Name )
{
int NumberOfRepeats = std::count( WaitLineIterator, WaitLine.end(), Name );
return NumberOfRepeats;
}

WaitLineIterator is defined as std::list< std::string >::iterator WaitLineIterator = WaitLine.begin()
Last edited on
Of course... you have the idea exactly. I would be disinclined to separate the begin() iterator and end() iterator though...

Also, keep in mind that the comparison will be case-sensitive. If you want case-insensitivity or any other odd condition, use std::count_if().

Hope this helps.
well my problem is that m_FindRepeats always returns 0

fixed the issue!
Last edited on
Topic archived. No new replies allowed.