Search code examples
c++vectorcontain

Vector. Checking to see if it contains "Key". C++


Possible Duplicate:
How to find an item in a std::vector?

Hey like the title suggests i would like to check to see if the vector contains the string "Key". I have been looking around on Google and i cant find anything in the vector library. Can anybody help me with this. Thanks in advance.


Solution

  • You can use std::find for that. Assuming you have an std::vector full of std::strings:

    #include <algorithm> // for std::find
    
    std::vector<std::string> v = ....;
    std::vector<std::string>::const_iterator it = std::find(v.begin(), v.end(), "Key");
    bool found = it != v.end();