#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()
auto it = find(vec.begin(),vec,end(), item)!
if(it != vec.end()){
int index = it - vec.begin();
}
#include <algorithm>
#include <vector>
if ( std::find(vec.begin(), vec.end(), item) != vec.end() )
do_this();
else
do_that();
#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;
}
it = find (vec.begin(), vec.end(), ser);
if (it != vec.end())
{
cout << "Element " << ser <<" found at position : " ;
cout << it - vec.begin() << " (counting from zero)
" ;
}
else{
cout << "Element not found.
";
}
Code Example |
---|
Cpp :: resize two dimensional vector c++ |
Cpp :: setw in c++ |
Cpp :: range of long long in c++ |
Cpp :: hello world C++, C plus plus hello world |
Cpp :: string to int arduino |
Cpp :: cpp take lambda as parameter |
Cpp :: binary string addition |
Cpp :: OPA in expanse |
Cpp :: what is _asm in C++ |
Cpp :: initializing 2d vector |
Cpp :: how to make a n*n 2d dynamic array in c++ |
Cpp :: c++ competitive programming mst |
Cpp :: Unsorted Linked list in c++ |
Cpp :: run c++ file putty |
Cpp :: Appending a vector to a vector in C++ |
Cpp :: change abstract title name latex |
Cpp :: c++ char to uppercase |
Cpp :: c++ string comparison |
Cpp :: string to int in c++ |
Cpp :: for in c++ |
Cpp :: number of words in c++ files |
Cpp :: min heap and max heap using priority queue |
Cpp :: c++ arithmetic operators |
Cpp :: header file for unordered_map in c++ |
Cpp :: restting a queue stl |
Cpp :: C++ break and continue |
Cpp :: C++ structure (Struct) |
Cpp :: c++ fstream |
Cpp :: cudamemcpy |
Cpp :: opencv open image c++ |