Answers for "check if vector contains a string c++"

C++
12

if vector contains value c++

#include <algorithm>

if(std::find(v.begin(), v.end(), x) != v.end()) {
    /* v contains x */
} else {
    /* v does not contain x */
}
Posted by: Guest on January-17-2020
1

check if element in std vector

#include <iostream>
#include <vector>
#include <algorithm>
 
int main()
{
    std::vector<int> v = { 4, 7, 5, 2, 6, 9 };
    int key = 6;
 
    if (std::count(v.begin(), v.end(), key))
        std::cout << "Element found";
    else
        std::cout << "Element not found";
 
    return 0;
}
Posted by: Guest on September-19-2020

Code answers related to "check if vector contains a string c++"

Browse Popular Code Answers by Language