I have an issue with searching in a vector. Let's say I have a vector, the idea is to use if and else statements to check each element and then print out a string message. So for example if there is a 1 at 0 then it should print out a message. The example below shows what I am trying to explain. If there is 1 at 0 then print out a message.
vector <int> myvec {1,2,3,4,5};
if (statement) {
cout << "The number 1 is at 0"
}
At the moment I have tried this:
vector <int> myvec {1,2,3,4,5};
if (find(myvec.begin(), myvec.end(), 3) != myvec.end()) {
cout << "yes it is there" << endl;
}
This only checks to see if 3 is in the vector but I want to find out if 1 is at 0.
Aucun commentaire:
Enregistrer un commentaire