|
-
November 1st, 2003, 12:57 AM
#6
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|