Search
 
SCRIPT & CODE EXAMPLE
 

CPP

c++ find index of an element

#include <iostream>
#include <vector> 
#include <iterator> 
#include <algorithm>  
using namespace std;

int main()
{
    vector<int> v = {1,2,3,4,6,4,5};
    // Get index of element from iterator
    int index = distance(v.begin(), find(v.begin(), v.end(), 4));
    cout << index;
}
Comment

c++ find index of element in array

int valueIndex = std::distance(
  yourArray, 
  std::find(
    yourArray, 
    yourArray + sizeof(yourArray) / sizeof(yourArray[0]),
    yourValueToFind));
Comment

c++ program to find the position of an element in an array

#include <iostream>
using namespace std;
 
Comment

PREVIOUS NEXT
Code Example
Cpp :: toString method in c++ using sstream 
Cpp :: qt make widget ignore mouse events 
Cpp :: put text on oled 
Cpp :: c++ Attribute Parser 
Cpp :: c++ loop trhought object 
Cpp :: how to change the value of a key in hashmp in c++ 
Cpp :: loop c++ 
Cpp :: c++ program to print odd numbers using loop 
Cpp :: 1768. Merge Strings Alternately leetcode solution in c++ 
Cpp :: C++ Program to Find the Range of Data Types using Macro Constants 
Cpp :: hierarchical inheritance in c++ employee 
Cpp :: cpp vscode multipe compilation 
Cpp :: rethrow exception c++ 
Cpp :: c++ hash map key count 
Cpp :: input c++ 
Cpp :: how to get last element of set 
Cpp :: if else in c++ 
Cpp :: C++ program to print all possible substrings of a given string 
Cpp :: evennumbers 1 to 100 
Cpp :: ternary operator in c++ 
Cpp :: options select from array 
Cpp :: how to take input in 2d vector in c++ 
Cpp :: c++ pointers 
Cpp :: queue 
Cpp :: double plus overload 
Cpp :: Numbers Histogram in c++ 
Cpp :: wgat is duble in c++ 
Cpp :: simple program for sign in and sign up in c++ 
Cpp :: arithmetic progression c++ 
Cpp :: identity 
ADD CONTENT
Topic
Content
Source link
Name
9+9 =