In Ruby I can do:
[1,2,3,4].include?(4) #=>True
In Haskell I can do :
4 `elem` [1,2,3,4] #=> True
What should I do in C++?
Here an example using find:
#include <iostream>
#include <vector>
#include <algorithm>
int main() {
std::vector<int> Num(4);
//insert values
Num[0]=1;
Num[1]=2;
Num[2]=3;
Num[3]=4;
std::vector<int>::iterator p = find(Num.begin(), Num.end(), 4);
if (p == Num.end())
std::cout << "Could not find 4 in the vector" << std::endl;
else
std::cout << "Have found 4 in the vector" << std::endl;
return 0;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With