-
Search text
How do you search a string of text for 1+ word(s)? I would assume that
Code:
template <class ForwardIterator1, class ForwardIterator2>
ForwardIterator1 search ( ForwardIterator1 first1, ForwardIterator1 last1,
ForwardIterator2 first2, ForwardIterator2 last2 );
only works for numerical values.
-
-
-
A string is a container of characters, so if you had a sequence of characters to search for then the search function you listed could work (I assume that's from the standard library). Note that this means that if you had more than one word then they would all have to be consecutive and part of a single search string.
Perhaps a better option for searching in strings is the find family of functions implemented for the standard string class (as linked to by linuxdude). They will likely give you more flexibility.
-
>> I would assume that
It's a generic algorithm - it works for any compliant type. If you want to use it for this, just pass it iterators to the beginning and end of the target and pattern, respectively. If it returns the end iterator of 'target', the search failed, otherwise just increment the begin iterator to 'target' and repeat the search until no more are found.