Search() algorythm

This is a discussion on Search() algorythm within the C++ Programming forums, part of the General Programming Boards category; You keep saying you are getting an error, but you haven't said what the error is. Is it a compile ...

  1. #16
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Katy, Texas
    Posts
    2,309
    You keep saying you are getting an error, but you haven't said what the error is.

    Is it a compile error or a runtime error? What is it!!!

    Todd

  2. #17
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Katy, Texas
    Posts
    2,309
    I found the COMPILE error. In red. (fixed)

    Code:
    #include <iostream>
    #include <vector> 
    #include <algorithm> 
    #include <string> 
    
    using namespace std ; 
    
    int main () {
      vector<string> myvector ;
      string::iterator it ; 
      
      string str = "search";
      string match = "ea";
      myvector.push_back(str);
    
      
      it = search(myvector[0].begin(), myvector[0].end(), match.begin(), match.end() );   // error
    
      if (it != myvector[0].end() )
        cout << "Match found at position: " << distance( myvector[0].begin(), it ) + 1  << endl ;
      else
        cout << "Match not found." << endl ;
      
      system("pause") ;
      return 0;
    }
    Since you are working with a string, you need a string iterator.

    Todd

  3. #18
    Registered User
    Join Date
    Dec 2007
    Posts
    796
    Thank you Todd and everybody, i'm learning a lot, much appreciated.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Logical errors with seach function
    By Taka in forum C Programming
    Replies: 4
    Last Post: 09-18-2006, 05:20 AM
  2. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  3. Tutorial review
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 03-22-2004, 08:40 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 09:33 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21