Thread: searching an element of a vector

  1. #1
    Registered User
    Join Date
    Dec 2004
    Posts
    50

    searching an element of a vector

    Is there any command with which I can find certain number in a vector? I want to avoid loops. I read somewhere about FIND function but I am simply not able to find it on internet. If there is the FIND function, I would appreciate if someone could tell me how it works.
    Thank you!!!

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    std::find
    Code:
    vector<int>::iterator result = find(vec.begin(), vec.end(), 12);
    
    if (result != vec.end())
         cout << "Value was found!" << endl;
    else
         cout << "Not Found!" << endl;

  3. #3
    Registered User
    Join Date
    Dec 2004
    Posts
    50

    12?????

    Code:
    vector<int>::iterator result = find(vec.begin(), vec.end(), 12);
    What does this 12 stand for?

  4. #4
    Registered User
    Join Date
    Dec 2004
    Posts
    50

    Now I get it

    It must be searched number

  5. #5
    Anti-Poster
    Join Date
    Feb 2002
    Posts
    1,401
    Quote Originally Posted by strickey
    Is there any command with which I can find certain number in a vector? I want to avoid loops. I read somewhere about FIND function but I am simply not able to find it on internet. If there is the FIND function, I would appreciate if someone could tell me how it works.
    Thank you!!!
    Are you thinking of this post? You might want to hold onto that link I gave you before.
    http://www.sgi.com/tech/stl/table_of_contents.html
    If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Vector of Strings help
    By CowsOFFmylawn in forum C++ Programming
    Replies: 7
    Last Post: 01-11-2009, 09:38 PM
  2. Vectors
    By naseerhaider in forum C++ Programming
    Replies: 11
    Last Post: 05-09-2008, 08:21 AM
  3. Logical errors with seach function
    By Taka in forum C Programming
    Replies: 4
    Last Post: 09-18-2006, 05:20 AM
  4. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  5. vector of pointers
    By gamer4life687 in forum C++ Programming
    Replies: 3
    Last Post: 09-26-2005, 10:49 PM