auto it = find(vec.begin(),vec,end(), item)!
if(it != vec.end()){
int index = it - vec.begin();
}
#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 :: factorial calculator c++ |
Cpp :: power of a number |
Cpp :: how to initialize vector |
Cpp :: Convert a hexadecimal number into decimal c++ |
Cpp :: max two numbers c++ |
Cpp :: c++ hello world linux |
Cpp :: c++ looping through a vector |
Cpp :: c plus plus |
Cpp :: login system with c++ |
Cpp :: quicksort geeksforgeeks |
Cpp :: c++ lettura file |
Cpp :: accumulate() in c++ |
Cpp :: c++ loop through list |
Cpp :: stl c++ |
Cpp :: c++ class template |
Cpp :: Youtube backlink generator tool |
Cpp :: c++ template |
Cpp :: what do you mean by smallest anagram of a string |
Cpp :: c++ inheritance constructor |
Cpp :: qt make widget ignore mouse events |
Cpp :: fill vector with zeros c++ |
Cpp :: onoverlapbegin ue4 c++ |
Cpp :: hierarchical inheritance in c++ employee |
Cpp :: what was the piep piper app |
Cpp :: volumeof a sphere |
Cpp :: log base e synthax c++ |
Cpp :: 2d array of zeros c++ |
Cpp :: remove element from c++ |
Cpp :: concatenate string in cpp |
Cpp :: how to take input in 2d vector in c++ |