Originally posted by Philip Nicoletti
Another one ...

Code:
#include <iostream>
#include <string>

int count_words(const std::string& input, const std::string& delims)
{
    int count = 0;

    std::string::size_type beg_index , end_index;

    beg_index = input.find_first_not_of(delims);

    while (beg_index != std::string::npos)
    {
       end_index = input.find_first_of(delims,beg_index);
       //std::cout << input.substr(beg_index,end_index-beg_index) << std::endl; // the word
       beg_index = input.find_first_not_of(delims,end_index); // get ready for next search
       ++count;
    }

    return count;
}

int main()
{
    std::string s = "yes-another word counter";

    std::cout << count_words(s," -") << std::endl;

    return 0;
}
excellent