lundi 9 octobre 2017

Using std::find to locate a randomly generated number in a vector

vector<int> v(n);

Given a vector of n randomly generated numbers, I want to set a random variable and determine if that variable is located in that vector using std::find algorithm.

int x = rand();
int p = std::find(v.begin(), v.end(), x); 

When I first run this code, I get an error along the lines of "cannot convert iterator to int in initialization".

Aucun commentaire:

Enregistrer un commentaire