Answers for "vectors find function in cpp"

C++
3

Using find in Vector c++

#include <algorithm>
#include <vector>
vector<int> vec; 
//can have other data types instead of int but must same datatype as item 
std::find(vec.begin(), vec.end(), item) != vec.end()
Posted by: Guest on December-04-2021
0

vector find

#include <bits/stdc++.h>
using namespace std;
int main()
{
    vector<int>v ;
    v.push_back(1);
    v.push_back(2);
    v.push_back(3);
    v.push_back(4);
    v.push_back(5);
    v.push_back(6);
    vector<int>::iterator it;
    it=find(v.begin(),v.end(),4);
    if(it!=v.end())
    cout<<it-v.begin()<<endl;
    return 0;
}
Posted by: Guest on April-29-2022

Code answers related to "vectors find function in cpp"

Browse Popular Code Answers by Language