Thread: Search text

  1. #1
    Registered User
    Join Date
    Jun 2009

    Search text

    How do you search a string of text for 1+ word(s)? I would assume that
    template <class ForwardIterator1, class ForwardIterator2>
       ForwardIterator1 search ( ForwardIterator1 first1, ForwardIterator1 last1,
                                 ForwardIterator2 first2, ForwardIterator2 last2 );
    only works for numerical values.

  2. #2
    Registered User linuxdude's Avatar
    Join Date
    Mar 2003
    Does this help?

  3. #3
    Registered User
    Join Date
    Jun 2009
    Yes, thanks!

  4. #4
    Registered User
    Join Date
    Jan 2005
    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.

  5. #5
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Waterloo, Texas
    >> 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.
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
        return std::pow
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. String search in two text files
    By ab-c in forum C Programming
    Replies: 2
    Last Post: 07-14-2008, 04:01 AM
  2. A bunch of Linker Errors...
    By Junior89 in forum Windows Programming
    Replies: 4
    Last Post: 01-06-2006, 02:59 PM
  3. How to use FTP?
    By maxorator in forum C++ Programming
    Replies: 8
    Last Post: 11-04-2005, 03:17 PM
  4. Tutorial review
    By Prelude in forum A Brief History of
    Replies: 11
    Last Post: 03-22-2004, 09:40 PM