Thread: STL algorithm question

  1. #1
    Reggie
    Guest

    STL algorithm question

    Does anyone know what algorithm or member function to use that returns a true or false if a container contains a specified item?

    Something like:

    if (contains(myVec,"John"))
    cout<<"MyVec contains the name John!"<<endl;

  2. #2
    Open to suggestions Brighteyes's Avatar
    Join Date
    Mar 2003
    Posts
    204
    >if (contains(myVec,"John"))
    Assuming your container can test for strings:
    Code:
    if (find(myVec.begin(), myVec.end(), "John") != myVec.end())
    p.s. What the alphabet would look like without q and r.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Noob STL question about Containers.
    By Swerve in forum C++ Programming
    Replies: 2
    Last Post: 03-15-2009, 12:02 PM
  2. What's wrong with STL rotate algorithm?
    By Mathsniper in forum C++ Programming
    Replies: 3
    Last Post: 12-09-2006, 08:54 AM
  3. n00b question regarding the Map Class in the STL library
    By Axegrinder#9 in forum C++ Programming
    Replies: 2
    Last Post: 12-17-2005, 09:40 PM
  4. STL container question
    By PJYelton in forum C++ Programming
    Replies: 8
    Last Post: 12-16-2002, 08:40 PM
  5. Algorithm question
    By PJYelton in forum C++ Programming
    Replies: 2
    Last Post: 10-28-2002, 10:52 AM